我有这个Tkinter类,它的工作完美,但这一部分,我不知道为什么,你们可以帮我吗?谢谢!它说我的功能是未定义的,它的定义
我正在使用pycharm。如果它改变了答案
> Error:
> self.dec = tk.Button(self, height=1, width=6, text="Decimal", command=fromHexDec(self.fromHex.get()))
NameError: global name 'fromHexDec' is not defined
Python代码不知道:
class Tkk(tk.Tk):
""""initiating the calculator"""
def __init__(self):
tk.Tk.__init__(self)
container = tk.Frame(self)
container.configure(bg="#eee", width=400, height=200)
container.pack(fill="both", expand=1, side="top")
self.label = tk.Label(self, text="Choose from one of bases to convert from below")
self.label.pack()
self.hexEnt = tk.Entry(self)
self.hex = tk.Button(self, height=1, width=9, text="Hexadecimal", command=self.hexa)
self.hexEnt.pack()
self.hex.pack()
def fromHexDec(self, num):
toDecimal(num, 16)
def hexa(self):
""""creating new variables"""
self.fromHex = tk.Entry(self)
self.bin = tk.Button(self, height=1, width=6, text="Binary")
self.oc = tk.Button(self, height=1, width=6, text="Octal")
self.dec = tk.Button(self, height=1, width=6, text="Decimal", command=fromHexDec(self.fromHex.get()))
self.label1 = tk.Label(self, text="You have chosen to convert from Hexa! Pick the base you want to convert to")
""""packing the variables"""
self.fromHex.pack()
self.label1.pack()
self.oc.pack()
self.dec.pack()
self.bin.pack()
"""destroying the current variables"""
self.hex.destroy()
self.hexEnt.destroy()
self.label.destroy()
frame = Tkk()
frame.mainloop()
注:定义的Tkinter在那里
'命令=拉姆达:self.fromHexDec(self.fromHex.get())'使用自我和lambda – abccd
什么拉姆达是什么意思? – guy
它在运行时创建一个函数 – abccd