1

我正在尝试创建一个基本的 Gmail 客户端,但我似乎在动态创建 Tkinter 按钮时遇到了问题。在我的课堂Main_Window上,我有一个方法叫做mainFun. 在这个方法中是这段代码,它试图创建 11 个编号为 1-11 的按钮。

for i in range(1,11):

    self.newmessage = Button(self, text = "%d" % i)
    Main_Window.entryFrame.append(self.newmessage)

烦人的是,我在运行代码时遇到错误。

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>> 
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
  File "/media/PI_USB/Email Send/Email Send GUI V2.py", line 111, in remember_Authen
    self.authen_credits()
  File "/media/PI_USB/Email Send/Email Send GUI V2.py", line 101, in authen_credits
    app = Main_Window()
  File "/media/PI_USB/Email Send/Email Send GUI V2.py", line 225, in __init__
    self.mainFun()
  File "/media/PI_USB/Email Send/Email Send GUI V2.py", line 281, in mainFun
    Main_Window.entryFrame.append(self.newmessage)
AttributeError: class Main_Window has no attribute 'entryFrame'

如果需要,这是我其余代码的 pastebin 链接:

http://pastebin.com/7J9newip

谢谢你!

4

1 回答 1

0
  • Main_Window.entryFrame似乎错字self.entryFrame
  • Tkinter.Frame没有append:在创建以框架为父的小部件时,将小部件附加到框架。然后调用widget.pack(..)widget.grid(..)

for i in range(1,11):
    self.newmessage = Button(self.entryFrame, text="%d" % i)
    self.newmessage.pack()
于 2013-06-18T06:05:26.430 回答