我是wxpython的新手,一直在试图在书籍中插入一些窗口部件(treebook,notebook,choicebook)我经常以放置在容器内的一些窗口部件没有响应事件。我不确定我做错了什么。以下是我的代码之一wxpython窗口部件内没有对事件作出响应
import wx
class ChoicePanelTwo(wx.Panel):
def __init__(self, parent, seed):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
self.SetBackgroundColour('blue')
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.List = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
for i in range(seed):
self.List.InsertStringItem(i, str(i))
sizer.Add(self.List, 1, wx.ALL|wx.EXPAND, 5)
self.SetSizer(sizer)
class ChoicePanelOne(wx.Panel):
def __init__(self, parent, seed):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
self.SetBackgroundColour('green')
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.RegisterList = wx.Choicebook(self, wx.ID_ANY)
sizer.Add(self.RegisterList, 1, wx.ALL|wx.EXPAND, 5)
for i in range(seed):
self.RegisterList.AddPage(ChoicePanelTwo(self, seed*50), str(i))
self.SetSizer(sizer)
class TreePanel(wx.Panel):
def __init__(self, parent, seed):
wx.Panel.__init__(self, parent, id=wx.ID_ANY)
self.SetBackgroundColour('cyan')
self.Choicbook = wx.Choicebook(self, wx.ID_ANY)
for i in range(seed):
self.Choicbook.AddPage(ChoicePanelOne(self, seed*2), str(i))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.Choicbook, 1, wx.ALL|wx.EXPAND, 5)
self.SetSizer(sizer)
class AppFrame(wx.Frame):
""" The main frame of the application
"""
title = 'Application'
WindowSize = (1024, 768)
seed = 2
def __init__(self):
wx.Frame.__init__(self, None, -1, self.title, size=self.WindowSize, style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN)
self.create_main_panel()
def create_main_panel(self):
self.panel = TreePanel(self, self.seed)
if __name__ == '__main__':
app = wx.PySimpleApp()
app.frame = AppFrame()
app.frame.Show()
app.MainLoop()
在此示例中。选择书和列表似乎工作。我做错了什么?
这是你的全部代码吗?你永远不会调用'Bind()'函数,也不会指定任何处理程序。你想要捕捉什么事件?当他们抓住他们时,你想让你的程序做什么? “不工作”是什么意思?请详细解释您的问题,包括您希望完成什么,您当前的行为是什么以及您尝试过的。 – acattle 2012-07-12 10:38:25
嘿,我想说的是,当用户试图改变最内层ChoiceBook的组合框时,它不会切换。当用户尝试滚动列表时,滚动条不会移动。我并不想捕捉任何事件,但想要切换选择页面并滚动。这似乎没有发生。 – lordsathish 2012-07-12 11:20:54