Bonjour,
En regardant la correction de l'exercice, il type les formules de conversion dans les fonctions avec str.
varTF.set(str(tF*1.8+32))
Je comprend pas du tout pourquoi il fait ca... Car sans str ca marche de la même façon.
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 from tkinter import * def convFar(event): #valeur de cette variable converti en fahrenheit tF=eval(champTC.get()) varTF.set(str(tF*1.8+32)) def convCel(event): tC=eval(champTF.get()) varTC.set(str((tC-32)/1.8)) fen=Tk() fen.title('fahrenheit/celsius') Label(fen,text="Temp. Celsius :").grid(row=0, column=0) varTC=StringVar() champTC=Entry(fen,textvariable=varTC) champTC.bind("<Return>",convFar) champTC.grid(row=0,column=1) #varTC.set("100.0") Label(fen,text="Temp. Fahrenheit :").grid(row=1,column=0) varTF=StringVar() champTF=Entry(fen,textvariable=varTF) champTF.bind("<Return>",convCel) champTF.grid(row=1,column=1) #varTF.set("212.0") fen.mainloop()
Partager