×

Créé une calculatrice iPhone avec python (KIVY)

Créé une calculatrice iPhone avec python (KIVY)

Dans ce tutoriel, on vas coder une calculatrice inspirer des iPhone avec python. On vas utiliser la librairie python kivy pour l’interface graphique.

Le code du programme est structurer de la façon suivante.

  • Le Fichier calculatrice.py qui gère tout ce qui est code python, notamment la creation et l’excution de l’application de base.
from kivy.app import App
from kivy.config import Config
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.properties import ObjectProperty

class Calculatrice(BoxLayout):
	
	def calculer(self, expression):
		if expression:
			try:
				self.display.text = str(eval(expression))
			except Exception:	
				self.display.text = 'Erreur'


	def reinitialiser(self, expression):
		if expression:
			self.display.text = ''

class calculatriceApp(App):
	def build(self):
		self.title = 'Calculatrice'	

Config.set('graphics','width','250')
Config.set('graphics','height','415')

calculatriceApp().run()

  • Le fichier calculatrice.kv qui contient tout ce qui est code kivy, notamment avec la definition de tout les bloc de l’interface graphique a savoir les boutons, les labels et autres.

#:import hex kivy.utils.get_color_from_hex

<BouttonGris@Button>:
	font_size: 25
	background_color: 0,0,0,0 
	canvas.before:
		Color:
			rgba: hex('#2e2b2b') if self.state == 'normal' else (0,.7,.7,1)
		Ellipse:
			pos: self.pos
			size: 60,60

<BouttonBlanc@Button>:
	font_size: 25
	background_color: 0,0,0,0 
	color: hex('#000000')
	canvas.before:
		Color:
			rgba: hex('#ffffff') if self.state == 'normal' else (0,.7,.7,1)
		Ellipse:
			pos: self.pos
			size: 60,60			

<BouttonJaune@Button>:
	font_size: 25
	background_color: 0,0,0,0 
	canvas.before:
		Color:
			rgba: hex('#ffa20e') if self.state == 'normal' else (0,.7,.7,1)
		Ellipse:
			pos: self.pos
			size: 60,60	

<BouttonRectangle@Button>:
	font_size: 25
	background_color: 0,0,0,0 
	canvas.before:
		Color:
			rgba: hex('#2e2b2b') if self.state == 'normal' else (0,.7,.7,1)
		RoundedRectangle:
			pos: self.pos
			size: 120,60		
			radius: [30,]		

Calculatrice:
	id:calculatrice
	display: input
	orientation: 'vertical'

	GridLayout:
		orientation: 'horizontal'
		size_hint: (1, 0.3)
		cols: 1
		rows: 1
		TextInput:
			id: input
			background_color: hex('#000000')
			foreground_color: hex('#ffffff')
			font_size: 30

	GridLayout:
		orientation: 'vertical'
		cols: 4
        
        BouttonBlanc:
        	text: 'C'
        	on_press: calculatrice.reinitialiser(input.text)	
        BouttonBlanc:
        	text: '+/-'
        	on_press: input.text += self.text
        BouttonBlanc:
        	text: '%'
        	on_press: input.text += self.text		
        BouttonJaune:
        	text: '/'
        	on_press: input.text += self.text				
        BouttonGris:
        	text: '7'
        	on_press: input.text += self.text		
        BouttonGris:
        	text: '8'
        	on_press: input.text += self.text	
        BouttonGris:
        	text: '9'
        	on_press: input.text += self.text		
        BouttonJaune:
        	text: '*'
        	on_press: input.text += self.text	
        BouttonGris:
        	text: '4'
        	on_press: input.text += self.text	
        BouttonGris:
        	text: '5'
        	on_press: input.text += self.text	
        BouttonGris:
        	text: '6'
        	on_press: input.text += self.text	
        BouttonJaune:
        	text: '-'
        	on_press: input.text += self.text	
        BouttonGris:
        	text: '1'
        	on_press: input.text += self.text
        BouttonGris:
        	text: '2'
        	on_press: input.text += self.text	
        BouttonGris:
        	text: '3'
        	on_press: input.text += self.text		
        BouttonJaune:
        	text: '+'
        	on_press: input.text += self.text	
        BouttonRectangle:
        	text: '0'
        	on_press: input.text += self.text	
        Label 	
        BouttonGris:
        	text: ','
        	on_press: input.text += self.text		
        BouttonJaune:
        	text: '='
        	on_press: calculatrice.calculer(input.text)									

La vidéo complète du tuto est déjà sur ma chaine YouTube. je vous invite a allez le visualiser pour mieux comprendre le code et le réutiliser. Merci.

91 commentaires

Avatar
Wkvuuh

costco canada cold and sinus top rated pill for itching types of allergy pills

Avatar
Kpeqyb

can ibuprofen help stomach ache avapro 300mg price

Avatar
Gybmbw

accutane 10mg over the counter accutane 20mg uk accutane 10mg generic

Avatar
Doisec

amoxicillin for sale online amoxil cost amoxil 1000mg uk

Avatar
Cnaxyj

sleeping pills to buy online generic phenergan

Avatar
Podbid

buy azithromycin 500mg pills order azithromycin 250mg for sale buy zithromax

Avatar
Jqdmmu

buy gabapentin without prescription order gabapentin without prescription

Avatar
Pqchtw

order azithromycin 250mg online cheap azipro for sale oral azithromycin

Avatar
Vdeaow

furosemide 100mg without prescription how to get furosemide without a prescription

Avatar
Qacwyb

order generic omnacortil 20mg prednisolone pills buy omnacortil 10mg sale

Avatar
Nvqbcm

cheap amoxil generic brand amoxicillin 1000mg amoxicillin pills

Avatar
Cbljyk

doxycycline 200mg us buy generic doxycycline

Avatar
Wjckmg

albuterol uk buy albuterol generic strongest over the counter asthma

Avatar
Gtmreu

buy augmentin 375mg sale buy augmentin without a prescription

Avatar
Nyfiqb

order generic synthroid 100mcg levothyroxine medication buy synthroid tablets

Avatar
Xduuyi

buy levitra generic vardenafil pill

Avatar
Asdewm

purchase clomid without prescription buy clomid pills for sale brand clomiphene 50mg

Avatar
Njhung

cheap rybelsus 14 mg cost rybelsus buy generic rybelsus 14mg

Avatar
Rbiurc

order prednisone 10mg buy prednisone generic prednisone 40mg sale

Avatar
Lzniyc

semaglutide 14 mg usa semaglutide 14mg generic buy rybelsus 14mg pill

Avatar
Azesll

order accutane 20mg isotretinoin cost accutane 40mg cheap

Avatar
Wujfpi

ventolin 2mg us purchase albuterol generic buy allergy pills onlin

Avatar
Fddxce

cheap amoxil generic amoxicillin 1000mg oral buy generic amoxicillin over the counter

Avatar
Iocgcf

clavulanate uk clavulanate us augmentin 625mg ca

Avatar
Afdlfj

cheap zithromax 250mg azithromycin drug cost azithromycin 500mg

Avatar
Rsrbdb

synthroid 75mcg price buy synthroid 150mcg generic levothyroxine order online

Avatar
Gkxthz

order omnacortil 40mg online cheap buy generic omnacortil 5mg buy omnacortil tablets

Avatar
Dwdhig

clomiphene pills serophene online order clomiphene 50mg pills

Avatar
Ucbqsn

neurontin 800mg generic order gabapentin online cheap gabapentin generic

Avatar
Celwan

order lasix 40mg generic lasix 40mg oral cost furosemide 40mg

Avatar
Zedgmc

viagra mail order order sildenafil viagra uk

Avatar
Ltejkx

buy semaglutide without a prescription rybelsus for sale online rybelsus 14mg uk

Avatar
Mnhugd

online slots online casinos for real money black jack card game free

Avatar
Udpvrv

buy vardenafil generic order vardenafil online cheap order vardenafil 10mg generic

Avatar
Hskzep

order lyrica generic lyrica 75mg pills purchase pregabalin online cheap

Avatar
Nmjtin

oral hydroxychloroquine order hydroxychloroquine 400mg without prescription hydroxychloroquine 200mg pill

Avatar
Ujlvxr

order triamcinolone 10mg pill order generic aristocort 10mg cheap aristocort

Avatar
Voqigv

cialis pharmacy purchasing cialis on the internet tadalafil 5mg sale

Avatar
Ahdbut

buy clarinex generic buy desloratadine 5mg clarinex online

Avatar
Rqmybd

toradol 10mg cheap colchicine drug order colchicine 0.5mg online cheap

Avatar
Uumxxt

medrol tablets methylprednisolone pill depo-medrol uk

Avatar
Sitnpg

buy propranolol generic buy cheap inderal buy clopidogrel 75mg sale

Avatar
Nkolso

buying essays assignments for sale mba essay service

Avatar
Plcfie

methotrexate medication purchase medex generic buy generic coumadin over the counter

Avatar
Gqxolp

meloxicam cost mobic pill celebrex pill

Avatar
Twyqwt

order reglan buy cozaar without prescription cozaar 25mg brand

Avatar
Lrbemv

flomax 0.4mg without prescription buy tamsulosin pills celecoxib 100mg generic

Avatar
Mgohxh

order esomeprazole 40mg generic topamax 100mg usa buy topiramate paypal

Avatar
Nktwfn

buy zofran 8mg generic buy ondansetron 8mg buy spironolactone tablets

Avatar
Yynwfo

imitrex 25mg uk levofloxacin order online levaquin 250mg without prescription

Avatar
Mkunjr

zocor 10mg usa zocor online buy valtrex medication

Avatar
Qmeprk

dutasteride canada buy ranitidine 150mg ranitidine 300mg uk

Avatar
Qazses

how to get ampicillin without a prescription vibra-tabs ca buy amoxil no prescription

Avatar
Xdajkn

purchase propecia sale finasteride 1mg sale forcan brand

Avatar
Cstvxv

cipro cost – cephalexin 250mg canada amoxiclav cheap

Avatar
Csglby

ciprofloxacin 500mg uk – purchase cipro buy augmentin 375mg pills

Avatar
Oizkzo

oral metronidazole 400mg – order amoxil pills order azithromycin generic

Avatar
Ijvisw

buy ciplox no prescription – doxycycline brand erythromycin pill

Avatar
Pwkoxy

ivermectin 12mg without prescription – order aczone gel tetracycline buy online

Avatar
Naoieq

buy valacyclovir pills for sale – nemasole buy online zovirax 400mg for sale

Avatar
Kbskrr

ivermectin 3mg for humans for sale – buy co-amoxiclav medication sumycin 250mg brand

Avatar
Tfgsgw

buy cheap flagyl – terramycin 250 mg generic buy azithromycin without prescription

Avatar
Bzcslm

buy ampicillin no prescription buy penicillin paypal cheap amoxicillin tablets

Avatar
Zswyco

furosemide 40mg pill – tacrolimus 5mg sale buy capoten 25mg for sale

Avatar
расследование qiwi

Lost QIWI wallet funds?
Let us be your guide in recovering what isrightfully yours.
Get in touch now and start the recovery journey.

Avatar
Ckihoh

generic glycomet 1000mg – oral cefadroxil 250mg lincomycin online order

Avatar
Blckci

retrovir brand – buy allopurinol generic zyloprim 100mg tablet

Avatar
Idavmq

oral clozapine 50mg – buy frumil 5mg for sale pepcid 40mg uk

Avatar
Ttfieb

quetiapine for sale online – cheap bupron SR pills eskalith us

Avatar
Frwzth

clomipramine 50mg oral – cost cymbalta 20mg buy doxepin 25mg

Avatar
Unsgzv

buy atarax without prescription – fluoxetine 40mg canada buy generic endep

Avatar
Waucnl

cheap clavulanate – buy linezolid 600mg generic brand ciprofloxacin

Avatar
Jwbhxf

cheap amoxicillin pills – ceftin 500mg tablet cipro 1000mg ca

Avatar
Prpezz

buy cleocin 300mg sale – order cefpodoxime 100mg for sale buy chloramphenicol tablets

Avatar
Wvmagk

buy azithromycin 250mg online cheap – metronidazole over the counter ciplox pills

Avatar
Fialzb

ivermectin 3mg over counter – buy ivermectin usa cefaclor 500mg us

Avatar
Qqpvge

albuterol 2mg without prescription – purchase advair diskus generic order theophylline 400 mg without prescription

Avatar
Zkmjdg

buy methylprednisolone 16 mg online – fml-forte price buy azelastine 10 ml

Avatar
Xtmksn

buy generic clarinex 5mg – ketotifen ca generic albuterol

Avatar
Jrvynf

cost glyburide 2.5mg – cost glucotrol 10mg buy dapagliflozin for sale

Avatar
Tckcyu

glucophage 1000mg over the counter – sitagliptin 100 mg price acarbose 50mg without prescription

Avatar
Yniyub

repaglinide 1mg price – purchase prandin sale order generic jardiance 10mg

Avatar
Lbgcaj

buy cheap terbinafine – fulvicin 250mg uk buy griseofulvin pill

Avatar
Qxegrl

purchase semaglutide – glucovance sale purchase desmopressin for sale

Avatar
binance Inscreva-se

Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

Avatar
Dzohyh

buy ketoconazole generic – buy generic lotrisone over the counter buy itraconazole 100mg for sale

Avatar
Vamydu

order digoxin online cheap – lasix online buy buy lasix 100mg online cheap

Avatar
Nnrbyj

lopressor 100mg without prescription – cheap inderal 10mg order nifedipine pill

Avatar
Yfoopt

purchase microzide online cheap – buy norvasc 5mg sale buy zebeta 5mg without prescription

Avatar
Kjhtwf

crestor suspect – rosuvastatin online capture caduet buy result

Avatar
Qsmfjf

cialis soft tabs pills hover – valif pills finish viagra oral jelly sensation

Laisser un commentaire