【发布时间】:2016-12-18 14:35:49
【问题描述】:
我该怎么办? 我想获得一个条目,但这是什么错误??????
def gt():
global e
string = e.get()
print(string)
def p():
b.destroy()
c.destroy()
w = Label(top, text="here are what you can use:")
w1 = Label(top, text="qwertyuiop[]asdfghjkl;zxcvbnm,./QWERTYUIOPASDFGHJKLZXCVBNM123456789")
w.pack()
w1.pack()
L1 = Label(top, text="give me the password")
L1.pack( side = LEFT)
e=Entry(top)
e.pack()
r = Button(top,text='okay',command=gt)
r.pack(side='bottom')
top.mainloop()
错误:
Traceback (most recent call last):
File "C:\Python33\lib\idlelib\run.py", line 121, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Python33\lib\queue.py", line 175, in get
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Users\Hadi\Desktop\t.py", line 51, in gt
string = e.get()
NameError: global name 'e' is not defined
如何修复此代码? e 已定义,但它说它不是!!!!?
【问题讨论】:
-
你确定
e是全局定义的,而不是在一个类或什么的?显示更多代码。 -
你将
e定义为函数p中的local变量
标签: python tkinter compiler-errors