I need to make a temperature converter for a class through tkinter. All the labels and buttons come up, but my button does not do anything when clicked. I have tried multiple different definitions of the command with no luck.
from tkinter import*
root=Tk()
label=Label(root,text="TEMPERATURE CONVERTER")
label.pack(side=TOP)
entry1=Entry(root)
entry1.place(x=300,y=50)
button1=Button(root,text="Convert")
button1.place(x=300,y=100)
label1=Label(root,text="Temperature in Celsius: ")
label1.place(x=100,y=50)
label2=Label(root,text="Temperature in Fahrenheit: ")
label2.place(x=100,y=150)
label3=Label(root)
label3.place(x=300,y=150)
var1=DoubleVar()
entry1=Entry(root,textvariable=var1)
def click1():
label3.config(str(var1.get)+ 32 * 1.8)
button1.bind("<Button-1>", click1)
You have multiple problems with your function. Are you even looking for the error messages? Because I got several when I ran your code.
TypeError
.var1.get
" is a function. To fetch the value, you have to call the it. str
, instead of multiplying the numbers and converting that.config
what thing to change. In your case, that's text
. This works, assuming you add root.mainloop()
at the end.
def click1(e):
label3.config(text=str(var1.get() * 1.8 + 32))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.