2013-03-23 19 views
0

我使用Python和PyGTK的PyGTK的继承产生误差treewiew和container.add

我有一个继承树视图类的类:

from gtk import TreeView 
class FolderView(TreeView): 

但是,当我把它添加到一个HBox容器:

folderView = FolderView 
hbox.add(folderView) 

我会在运行时出现以下错误

TypeError: Gtk.Container.add() argument 1 must be gtk.Widget, not GObjectMeta 

通过反思,我已经确认gtk.Widget在继承路径中,所以在我的脑海中它应该工作。任何人都可以告诉我哪一部分的Python和pygtk我不理解?

回答

0

它应该是folderView = FolderView()。请参见下面的交互提示结果:

>>> from gtk import TreeView 
>>> class FolderView(TreeView): 
...  pass 
... 
>>> fw = FolderView() 
>>> from gtk import HBox 
>>> hbox = HBox() 
>>> hbox.add(FolderView) # this is passing the class 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: Gtk.Container.add() argument 1 must be gtk.Widget, not GObjectMeta 
>>> hbox.add(FolderView()) # and this is actually creating an instance 
>>> hbox.get_children() 
[<FolderView object at 0x9ab1964 (GtkTreeView at 0x992a240)>] 
+0

我红着脸....我完全错过了,这是不实例化。猜猜这对我来说有点晚了,我应该去睡觉。感谢您的帮助。 – user2203199 2013-03-23 20:56:06

+0

欢迎来到Stackoverflow。 – phineas 2013-03-23 20:57:56