出现错误的代码如下:
import Tkinter
def CreateGUI():
top = Tkinter.Tk()
rec_label = Tkinter.Label(top, text='RecMessage', bg='orange')
rec_label.pack(fill=X,side=TOP)
rec_text = Tkinter.Text(top).pack(side=LEFT)
if __name__ == '__main__':
CreateGUI()
Tkinter.mainloop()
Traceback (most recent call last):
File "D:\Python\net_helper.py", line 10, in
CreateGUI()
File "D:\Python\net_helper.py", line 6, in CreateGUI
rec_label.pack(fill=X,side=TOP)
NameError: global name 'TOP' is not defined
代码
rec_label.pack(fill=X,side=TOP)
中的“X”和
rec_text = Tkinter.Text(top).pack(side=LEFT)
中的“LEFT”都是同样的错误。
将代码修改为
import Tkinter
def CreateGUI():
top = Tkinter.Tk()
rec_label = Tkinter.Label(top, text='RecMessage', bg='orange')
rec_label.pack(fill=Tkinter.X,side=Tkinter.TOP)
rec_text = Tkinter.Text(top).pack(side=Tkinter.LEFT)
if __name__ == '__main__':
CreateGUI()
Tkinter.mainloop()