在列表中存储帧

时间:2013-05-09 13:50:54

标签: python list tk

我正在尝试将帧存储在一个列表中,这样我可以将我的小部件3到3放在彼此的顶部,在它们之间留出一小块空间

但我似乎无法使其发挥作用。

代码:

self.cboCombo = []
self.frame_type = []
for x in range(7):
   self.cboCombo.append([])
      for y in range(3):
         self.cboCombo[x].append([])        

for i in range(7):
   self.frame_type.append(i)
   self.frame_type[i] = Frame(self.frame_type)
   self.frame_type[i].pack(side=TOP, expand=1, ipady= 11)
   self.cboCombo[i][0] = ttk.Combobox(self.frame_type[i], values=self.valCombo,             textvariable=self.varCombo[1][0])
   self.cboCombo[i][0].pack(padx= 5)
   self.cboCombo[i][1] = ttk.Combobox(self.frame_type[i], values=self.valCombo, textvariable=self.varCombo[1][1])
   self.cboCombo[i][1].pack(padx= 5)
   self.cboCombo[i][2] = ttk.Combobox(self.frame_type[i], values=self.valCombo, textvariable=self.varCombo[1][2])
   self.cboCombo[i][2].pack(padx= 5)

错误讯息:

  File "File.py", line 89, in __init__
    self.frame_type[i] = Frame(self.frame_type)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 2453, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1965, in __init__
    BaseWidget._setup(self, master, cnf)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1943, in _setup
    self.tk = master.tk
AttributeError: 'list' object has no attribute 'tk'

是否有解决方案或其他方式来完成它?

谢谢

1 个答案:

答案 0 :(得分:0)

关注Tkinter文档:

w = Frame ( master, option, ... )

Parameters:
    master: This represents the parent window.

您的self.frame_type看起来不像对象代表父窗口。