python中tkinter中新手一个常见的错误
2013-04-23 23:36
316 查看
from tkinter import *
a = Label(text = 'hello').pack()
a.mainloop()
这样的写法会导致AttributeError: 'NoneType' object has no attribute 'mainloop'
原因如下:
a = Label(text = 'hello').pack()看似将a指向一个Label,其实并不是。a指向的是pack()返回的一个None,
所以就导致了上述错误。所以a = Label(text = 'hello').pack是一种非常不好的书写方法。要么直接使用Labe(text = 'hello').pack()
要么:
a = Label(text = 'hell0')
a.pack()
a = Label(text = 'hello').pack()
a.mainloop()
这样的写法会导致AttributeError: 'NoneType' object has no attribute 'mainloop'
原因如下:
a = Label(text = 'hello').pack()看似将a指向一个Label,其实并不是。a指向的是pack()返回的一个None,
所以就导致了上述错误。所以a = Label(text = 'hello').pack是一种非常不好的书写方法。要么直接使用Labe(text = 'hello').pack()
要么:
a = Label(text = 'hell0')
a.pack()
相关文章推荐
- 17个新手常见Python运行时错误
- python的Error集,17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17 个新手常见 Python 运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 【python】17个新手常见Python运行时错误
- 【Python】17个新手常见Python运行时错误
- Python运行的17个时新手常见错误小结
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 17个新手常见Python运行时错误
- 【转载】17个新手常见Python运行时错误
- 17个新手常见Python运行时错误