当我尝试运行以下代码时。我收到了错误。
import wx
from wx.lib.agw.hypertreelist import HyperTreeList
class test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title='htl', size=(955,550))
self.CenterOnScreen()
self.tree = HyperTreeList(self, style =
wx.TR_FULL_ROW_HIGHLIGHT |
wx.TR_HAS_VARIABLE_ROW_HEIGHT)
# create columns
self.tree.AddColumn("c1", 120)
self.tree.AddColumn("c1")
self.tree.AddColumn("c3", 120)
self.tree.AddColumn("c4")
self.tree.AddColumn("c5")
self.tree.AddColumn("c6")
self.tree.AddColumn("c7")
self.tree.AddColumn("c8")
self.tree.AddColumn("c9")
root = self.tree.AddRoot("root")
rc = self.tree.AppendItem(root, "child1")
rc2 = self.tree.AppendItem(root, "child2")
gauge = wx.Gauge(self.tree.GetMainWindow(), -1, 100,
style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
gauge.SetValue(25) *#can we add this value over/within gauge
control/window*
gauge.SetDimensions(100, 100, 100, 20)
self.tree.SetItemWindow(rc2, gauge, 7) #here is problem
self.tree.Expand(root)
#end def
#end test
class App(wx.App):
"""Application class."""
def OnInit(self):
self.frame = test()
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main():
app = App()
app.MainLoop()
if __name__ == '__main__':
main()
我收到了这个错误
Traceback (most recent call last):
File "/root/workspace/test/src/test.py", line 61, in <module>
main()
File "/root/workspace/test/src/test.py", line 57, in main
app = App()
File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_core.py",
line 7974, in __init__
self._BootstrapApp()
File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_core.py",
line 7548, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "/root/workspace/test/src/test.py", line 51, in OnInit
self.frame = test()
File "/root/workspace/test/src/test.py", line 39, in __init__
self.tree.SetItemWindow(rc2, gauge, 7)
File
"/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/lib/agw/hypertreelist.py",
line 3282, in delegate
return getattr(self._main_win, method)(*args, **kwargs)
File
"/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/lib/agw/hypertreelist.py",
line 1414, in SetItemWindow
item.SetWindow(window, column)
File
"/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/lib/agw/hypertreelist.py",
line 1055, in SetWindow
self._wnd[column] = wnd
IndexError: list assignment index out of range
我做错了什么?
其次,我们可以在量表控件中添加百分比数字。
问候,
答案 0 :(得分:1)
这是一个在SVN中修复的已知错误 - http://trac.wxwidgets.org/ticket/11708
下载http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/AGW/agw/hypertreelist.py并直接在您的应用中使用它,而不是使用wx中的那个。
答案 1 :(得分:0)
几个检查站
wx.TR_FULL_ROW_HIGHLIGHT
,120
&amp;中删除self.tree.AddColumn("c1", 120)
self.tree.AddColumn("c3", 120)