Objectif : Créer une mini calculatrice en Python.
Je vous donne un code de départ. il a pour avantage de fonctionner mais demande beaucoup d'amélioration ....
from tkinter import* from math import * fen=Tk() a,b,op,t=0,0,'',0 def x1(): nombre(1.) def x2(): nombre(2.) def aplus(): global op op='+' def nombre(x): global a,b,t,z if t==0: a=x t=1 z.set(str(a)) else: b=x t=0 z.set(str(b)) def calc(): global a,b,t,z,op if op=='+': z.set(str(a+b)) Button(fen, text = '1', command= x1).pack() Button(fen, text = '2', command= x2).pack() Button(fen, text= '+', command = aplus).pack() Button(fen, text= '=', command = calc).pack() z = StringVar() entree=Entry(fen,textvariable=z) entree.pack() z.set("0.") fen.mainloop()