我要做什么:
带有tkinter的GUI,可以将摄氏温度转换为华氏温度。
正在发生的事情
窗口本身正在工作,但是当我尝试使用按钮调用calc
函数时,它将返回错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
TypeError: calc() missing 1 required positional argument: 'grausC'
我的代码:
from tkinter import *
janela = Tk()
janela.title("Conversao")
janela.geometry("600x600")
def calc(grausC):
graus = float(grausC.get())
Fahrenheit = (graus * 9/5 + 32)
lb3=Label(janela, text=CalcF)
lb3.place(x=200, y=200)
titulo=Label(janela, text="Conversao de Celsius para Fahrenheit", font=("Verdana 20 underline"))
titulo.place(x=20, y=20)
grausC = Entry(janela)
grausC.place(x=200,y=150)
lb1=Label(janela, text="Graus em Celsius:")
lb1.place(x=70, y=150)
lb2=Label(janela, text="Graus em Fahrenheit:")
lb2.place(x=70, y=200)
btn=Button(janela, text= "Calcular", command=calc)
btn.place(x=100, y = 250)
janela.mainloop()
答案 0 :(得分:1)
解决了我的问题。功能定义不正确。
def calc():
graus = float(grausC.get())
Fahrenheit = (graus * 9/5 + 32)
FahrenheitS = str(Fahrenheit)
lb3=Label(janela, text=FahrenheitS)
lb3.place(x=200, y=200)