我正在学习wxpython,并对按钮有疑问。我的文件中有一个主类,它调用另一个形成笔记本的类,调用另一个类来构建笔记本页面的布局。我正和其他人一起编程,所以我要用别人的方式编程。
我的问题是,单击“添加按钮”时我没有做任何事情。也许它与我调用按钮的方式有关?
“self.notebook.PageOne.addbutton.Bind(wx.EVT_BUTTON,self.on_add_to_plotlist)”
的Tx
我的代码:
class TabPanelMicroanalysis(wx.Panel):
def __init__(self, parent, id):
# # general panel information
#wx.Frame.__init__(self, parent, id)
wx.Panel.__init__(self, parent, id)
# list with available measurements + button to add to plot
self.lbltempmeasurements = wx.StaticText(self, label="Available measurements:")
self.tempmeasurements = ObjectListView(self, wx.ID_ANY,style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.tempmeasurements.SetColumns(microanalysis_options.TempMeasColumndefs)
self.tempmeasurements.CreateCheckStateColumn(0)
self.addbutton = wx.Button(self, wx.ID_ANY, "Add to plot")
class NotebookMA(wx.Notebook):
def __init__(self, parent,id):
wx.Notebook.__init__(self, parent, id)
# Create the first tab and add it to the notebook
self.PageOne = TabPanelMicroanalysis(self, wx.ID_ANY)
self.AddPage(self.PageOne, "Microanalysis name")
class Main(wx.Frame):
#Frame that holds all other widgets
def __init__(self, parent = None, id = -1, notify_channel = "chanMicroanalysis", ** kwargs):
#general panel information
wx.Frame.__init__(self, parent, wx.ID_ANY)
self.SetTitle('Microanalysis')
self.panel = wx.Panel(self, wx.ID_ANY)
pub.subscribe(self.on_message, notify_channel)
# add menubar
self.menubar = menubar_view(self, wx.ID_ANY)
#make notebook
self.notebook = NotebookMA(self.panel, wx.ID_ANY)
self._do_layout()
pub.sendMessage("PyShark", dict(caller=self, module="microanalyse_controller", package="Controllers"))
def _do_layout(self):
self.vsizer = wx.BoxSizer(wx.VERTICAL)
self.vsizer.Add(self.notebook,1,wx.EXPAND)
self.panel.SetSizer(self.vsizer)
self.SetMenuBar(self.menubar)
self.Maximize()
self.Show()
def _do_bindings(self):
#print "testje"
self.notebook.PageOne.addbutton.Bind(wx.EVT_BUTTON, self.on_add_to_plotlist)
# EVENT handlers -------------------------------------------------------------------------------------------------------
def on_message(self, message):
pass
def on_add_to_plotlist(self, event):
objectsAddPlotList = self.notebook.PageOne.tempmeasurements.GetSelectedObjects()
pub.sendMessage(self.notify_channel,
Container(type="EVT_ADD_TO_PLOTLIST", origin=self.notebook.PageOne.tempmeasurements, data=objectsAddPlotList))
答案 0 :(得分:1)
好的,没关系。我忘了放
self._do_bindings()
在我的主要课程中:s