这些天我学习了“编程python”这本书。当我运行示例时,我遇到了问题。shell向我显示了错误:
AttributeError:“NoneType”对象没有属性“pack”
但是,我从书中复制了确切的代码。我是 Python 的大一新生。我尝试自己修复它,但我失败了。所以我希望任何人都可以帮助我。
谢谢 !!!!!!
代码:</p>
#File test.py
from tkinter import *
from tkinter.messagebox import showinfo
def MyGui(Frame):
def __init__(self, parent = None):
Frame.__init__(self, parent)
button = Button(self, text='press', command=reply)
button.pack()
def reply(self):
showinfo(title = 'popup',message ='Button pressed!')
if __name__ == '__main__':
window = MyGui()
window.pack()
window.mainloop()
#File test2.py
from tkinter import *
from test import MyGui
mainwin = Tk()
Label(mainwin,text = __name__).pack()
popup = Toplevel()
Label(popup,text = 'Attach').pack(side = LEFT)
MyGui(popup).pack(side=RIGHT)
mainwin.mainloop()