【发布时间】:2013-11-25 15:37:18
【问题描述】:
我对 Python 还很陌生,刚开始玩 tkinter。
运行下面的代码,我得到but1.pack() 的属性错误(NoneType 对象没有属性pack)。但据我所知,这个错误对窗口的功能没有影响,它仍然是packing 按钮。窗口仍然出现,所有按钮都按预期运行。
搜索我可以看到其他人有这个错误,但给出的答案都没有解决我的问题。希望你能帮忙。
代码:
import tkinter
import ctypes
lst=[]
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
def closewindow():
window.destroy()
def btn1():
lst.append("Button1")
def btn2():
lst.append("Button2")
window = tkinter.Tk()
size = str(screensize[0])+'x'+str(screensize[1])
window.geometry(size)
but1 = tkinter.Button(window, text="Button1", command=btn1).grid(column = 1, row = 1)
but2 = tkinter.Button(window, text="Button2", command=btn2).grid(column = 2, row = 1)
ext = tkinter.Button(window, text="Stop", command=closewindow).grid(column = 3, row = 1)
but1.pack()
but2.pack()
ext.pack()
window.mainloop()
回调;
Traceback (most recent call last):
File "C:\Python33\temp.py", line 59, in <module>
but1.pack()
AttributeError: 'NoneType' object has no attribute 'pack'
【问题讨论】:
标签: python windows python-3.x tkinter windows-xp