【发布时间】:2014-12-25 16:08:19
【问题描述】:
我正在尝试制作一个程序以在 GUI 中显示标签 'HI',只有在同一 GUI 中单击按钮 'CLICK' 后。
我的代码:
import Tkinter as tki
class App(object):
def __init__(self,root):
self.root = root
txt_frm = tki.Frame(self.root, width=900, height=900)
txt_frm.pack(fill="both", expand=True)
button3 = tki.Button(txt_frm,text="CLICK", command = self.retrieve_inpu)
button3.grid(column=0,row=2)
def retrieve_inpu(self):
label = tki.Label(txt_frm,text='HI')
label.grid(column=0,row=3)
root = tki.Tk()
app = App(root)
root.mainloop()
但我得到错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:/Python27/teste.py", line 14, in retrieve_inpu
label = tki.Label(txt_frm,text='HI')
NameError: global name 'txt_frm' is not defined
请帮我在点击按钮'CLICK'后在同一GUI中显示标签'HI'。
【问题讨论】: