关于wxpython listctrl的一个问题
我得到了一个用wxpython实现的GUI应用程序,在主窗口上,有一个listctrl用于显示文件的名称。一开始它是空的。用户单击“文件”,然后“打开”,然后选择要打开的文件,当通过单击“确定”按钮完成此操作时,文件名应该显示在 listctrl 中。但这似乎行不通。我使用 print
子句来检查 print
子句是否有效。这是我的代码:
def OnDisplay(self):
print "On display called"
self.lc1.InsertStringItem(0, "level 1")
self.lc1.InsertStringItem(1, "level 2")
self.lc1.SetBackgroundColour(wx.RED)
print self.lc1.GetItemText(0)
print self.lc1.GetItemText(1)
self.lc1.Refresh()
lc1
是listctrl,在主窗口启动时一开始就初始化了,但是当OnDisplay
被触发,print "On display called"
起作用,并且以下两个 print
子句也起作用。但主窗口上的listctrl没有改变,我的意思是,没有显示level 1
和level 2
,listctrl的背景也没有变成红色,请问是什么原因?非常感谢!
I got a GUI application implemented in wxpython, on the main window, there is a listctrl used to dispaly the names of the files. it was empty at the very beginning. the user clicks the "File", then "open", then chooses a file to open, when this is done by clicking on the "ok" button, the names of the file is supposed to be display in the listctrl. But it seems that this does not work. I used a print
clause to check, the print
clause works. Here are my codes:
def OnDisplay(self):
print "On display called"
self.lc1.InsertStringItem(0, "level 1")
self.lc1.InsertStringItem(1, "level 2")
self.lc1.SetBackgroundColour(wx.RED)
print self.lc1.GetItemText(0)
print self.lc1.GetItemText(1)
self.lc1.Refresh()
lc1
is the listctrl, it was initialized at the very beginning when the main window was lauched, but when the OnDisplay
was triggered, the print "On display called"
works, and the following two print
clauses also work. but the listctrl on the main window did not change, i mean, did not show the level 1
and level 2
, nor did the background of the listctrl was changed to red, what is the reason please? many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个可在 Windows 7、Python 2.6、wx 2.8 上运行的示例。
Here is a runnable example that works on Windows 7, Python 2.6, wx 2.8.