1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| from tkinter import *
from math import *
import tkinter as tk
#importation de la bibliotheque Tkinter et math
def evaluer(*event):
chaine.configure(text = "resultat=" + str(eval(entree.get())))
#_______________________________________________________________
fenetre = Tk()
fenetre.geometry("400x500") #definis la taille de la fenetre
fenetre.title ('Calculatrice') #Nom de la fenetre
#__________
entree = tk.Entry(fenetre)
entree.bind("<Return>", evaluer)#fait en sorte qu'un evenement se produit lorsque l'on appuye sur enter
bouegale = Button(fenetre,text='=',command=evaluer, width =8)
bouegale.grid(row =7, column =2)
#__________
chaine = Label(fenetre)#Modifie l'attribut "texte" lors de l'evenement
entree.grid(row=0, column=1)
chaine.grid()
def do_action1():
entree.insert('end',1)
def do_action2():
entree.insert('end',2)
def do_action3():
entree.insert('end',3)
def do_action4():
entree.insert('end',4)
def do_action5():
entree.insert('end',5)
def do_action6():
entree.insert('end',6)
def do_action7():
entree.insert('end',7)
def do_action8():
entree.insert('end',8)
def do_action9():
entree.insert('end',9)
def do_action0():
entree.insert('end',0)
def do_actionpoint():
entree.insert('end','.')
def do_actionplus():
entree.insert('end','+')
def do_actionmoins():
entree.insert('end','-')
def do_actionfois():
entree.insert('end','*')
def do_actiondiviser():
entree.insert('end','/')
bou1 = Button(fenetre, text='1',command=do_action1, width =8)
bou1.grid(row =4, column =0)
bou2 = Button(fenetre, text='2',command=do_action2 ,width =8)
bou2.grid(row =5, column =0)
bou3 = Button(fenetre, text='3',command=do_action3 , width =8)
bou3.grid(row =6, column =0)
bou4 = Button(fenetre, text='4',command=do_action4 , width =8)
bou4.grid(row =4, column =1)
bou5 = Button(fenetre, text='5',command=do_action5, width =8)
bou5.grid(row =5, column =1)
bou6 = Button(fenetre, text='6',command=do_action6, width =8)
bou6.grid(row =6, column =1)
bou7 = Button(fenetre, text='7',command=do_action7, width =8)
bou7.grid(row =4, column =2)
bou8 = Button(fenetre, text='8',command=do_action8, width =8)
bou8.grid(row =5, column =2)
bou9 = Button(fenetre, text='9',command=do_action9, width =8)
bou9.grid(row =6, column =2)
bou0 = Button(fenetre, text='0', width =8)
bou0.grid(row =7, column =1)
boupoint = Button(fenetre, text=',',command=do_actionpoint, width =8)
boupoint.grid(row =7, column =0)
entree.bind("<Return>" , evaluer)
bouplus = Button(fenetre, text='+',command=do_actionplus, width =8)
bouplus.grid(row =4, column =3)
boumoins = Button(fenetre, text='-',command=do_actionmoins, width =8)
boumoins.grid(row =5, column =3)
boufois = Button(fenetre, text='x',command=do_actionfois, width =8)
boufois.grid(row =6, column =3)
boudiviser = Button(fenetre, text='/',command=do_actiondiviser, width =8)
boudiviser.grid(row =7, column =3)
#Placement des boutons
fenetre.mainloop() |
Partager