【问题标题】:wxpython + how to bind button when using different classeswxpython +使用不同类时如何绑定按钮
【发布时间】:2017-05-04 09:46:52
【问题描述】:

我正在学习 wxpython 并且对按钮有疑问。我的文件中有一个主类,它调用另一个形成笔记本的类,该类调用另一个为笔记本页面进行布局的类。我和其他人一起编程,所以我必须使用别人的编程方式。

我的问题是单击“添加按钮”时它没有做任何事情。也许这与我调用按钮的方式有关?

“self.notebook.PageOne.addbutton.Bind(wx.EVT_BUTTON, self.on_add_to_plotlist)”

发送

我的代码:

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))

【问题讨论】:

    标签: python class button wxpython


    【解决方案1】:

    好吧,没关系。忘记放了

    self._do_bindings()
    

    在我的主要课程中:s

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 1970-01-01
      • 2019-07-21
      • 2014-06-29
      • 2023-03-11
      • 2011-06-25
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多