Python使用Tkinter错误,NameError: global name 'TOP' is not defined

出现错误的代码如下:

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 <module>
    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()

即可解决上面的问题!


上面的代码报错 [ WARN:0@8.611] global loadsave.cpp:244 cv::findDecoder imread_(''): can't open/read file: check file path/integrity Exception in Tkinter callback Traceback (most recent call last): File "E:\python\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "D:\pythonProject2\venv\1.py", line 11, in open_image processed_image, cell_count = process_image(image) File "D:\pythonProject2\venv\1.py", line 21, in process_image return processed_image, cell_count NameError: name 'processed_image' is not defined Exception in Tkinter callback Traceback (most recent call last): File "E:\python\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "D:\pythonProject2\venv\1.py", line 11, in open_image processed_image, cell_count = process_image(image) File "D:\pythonProject2\venv\1.py", line 21, in process_image return processed_image, cell_count NameError: name 'processed_image' is not defined [ WARN:0@27.282] global loadsave.cpp:244 cv::findDecoder imread_(''): can't open/read file: check file path/integrity Exception in Tkinter callback Traceback (most recent call last): File "E:\python\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "D:\pythonProject2\venv\1.py", line 11, in open_image processed_image, cell_count = process_image(image) File "D:\pythonProject2\venv\1.py", line 21, in process_image return processed_image, cell_count NameError: name 'processed_image' is not defined Process finished with exit code 0
06-08
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值