<tfoot id='GRHoI'></tfoot>
    1. <legend id='GRHoI'><style id='GRHoI'><dir id='GRHoI'><q id='GRHoI'></q></dir></style></legend>

      <small id='GRHoI'></small><noframes id='GRHoI'>

      <i id='GRHoI'><tr id='GRHoI'><dt id='GRHoI'><q id='GRHoI'><span id='GRHoI'><b id='GRHoI'><form id='GRHoI'><ins id='GRHoI'></ins><ul id='GRHoI'></ul><sub id='GRHoI'></sub></form><legend id='GRHoI'></legend><bdo id='GRHoI'><pre id='GRHoI'><center id='GRHoI'></center></pre></bdo></b><th id='GRHoI'></th></span></q></dt></tr></i><div id='GRHoI'><tfoot id='GRHoI'></tfoot><dl id='GRHoI'><fieldset id='GRHoI'></fieldset></dl></div>

      • <bdo id='GRHoI'></bdo><ul id='GRHoI'></ul>

        获取调用事件的按钮名称的最佳方法?

        时间:2023-10-09

        <small id='tb8pC'></small><noframes id='tb8pC'>

        1. <tfoot id='tb8pC'></tfoot>
          <legend id='tb8pC'><style id='tb8pC'><dir id='tb8pC'><q id='tb8pC'></q></dir></style></legend>
              <i id='tb8pC'><tr id='tb8pC'><dt id='tb8pC'><q id='tb8pC'><span id='tb8pC'><b id='tb8pC'><form id='tb8pC'><ins id='tb8pC'></ins><ul id='tb8pC'></ul><sub id='tb8pC'></sub></form><legend id='tb8pC'></legend><bdo id='tb8pC'><pre id='tb8pC'><center id='tb8pC'></center></pre></bdo></b><th id='tb8pC'></th></span></q></dt></tr></i><div id='tb8pC'><tfoot id='tb8pC'></tfoot><dl id='tb8pC'><fieldset id='tb8pC'></fieldset></dl></div>
                <tbody id='tb8pC'></tbody>

                  <bdo id='tb8pC'></bdo><ul id='tb8pC'></ul>
                  本文介绍了获取调用事件的按钮名称的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在以下代码中(受 this 片段的启发),我使用了一个事件处理程序 buttonClick 以更改窗口的标题.目前,我需要评估事件的 Id 是否对应于按钮的 Id.如果我决定添加 50 个按钮而不是 2 个,这种方法可能会变得很麻烦.有没有更好的方法来做到这一点?

                  In the following code (inspired by this snippet), I use a single event handler buttonClick to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to add 50 buttons instead of 2, this method could become cumbersome. Is there a better way to do this?

                  import wx
                  
                  class MyFrame(wx.Frame):
                      def __init__(self):
                          wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton',
                              pos=(300, 150), size=(300, 350))
                          self.panel1 = wx.Panel(self, -1)
                  
                          self.button1 = wx.Button(self.panel1, id=-1,
                              pos=(10, 20), size = (20,20))
                          self.button1.Bind(wx.EVT_BUTTON, self.buttonClick)
                  
                          self.button2 = wx.Button(self.panel1, id=-1,
                              pos=(40, 20), size = (20,20))
                          self.button2.Bind(wx.EVT_BUTTON, self.buttonClick)
                  
                          self.Show(True)
                  
                      def buttonClick(self,event):
                          if event.Id == self.button1.Id:
                              self.SetTitle("Button 1 clicked")
                          elif event.Id == self.button2.Id:
                              self.SetTitle("Button 2 clicked")            
                  
                  application = wx.PySimpleApp()
                  window = MyFrame()
                  application.MainLoop()
                  

                  推荐答案

                  你可以给按钮一个名字,然后在事件处理程序中查看这个名字.

                  You could give the button a name, and then look at the name in the event handler.

                  当你制作按钮时

                  b = wx.Button(self, 10, "Default Button", (20, 20))
                  b.myname = "default button"
                  self.Bind(wx.EVT_BUTTON, self.OnClick, b)
                  

                  当按钮被点击时:

                  def OnClick(self, event):
                      name = event.GetEventObject().myname
                  

                  这篇关于获取调用事件的按钮名称的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 Python 从 Selenium 的重定向链中获取中间 下一篇:单击按钮并按回车时调用相同的函数

                  相关文章

                  最新文章

                • <tfoot id='Ch56r'></tfoot>

                    <i id='Ch56r'><tr id='Ch56r'><dt id='Ch56r'><q id='Ch56r'><span id='Ch56r'><b id='Ch56r'><form id='Ch56r'><ins id='Ch56r'></ins><ul id='Ch56r'></ul><sub id='Ch56r'></sub></form><legend id='Ch56r'></legend><bdo id='Ch56r'><pre id='Ch56r'><center id='Ch56r'></center></pre></bdo></b><th id='Ch56r'></th></span></q></dt></tr></i><div id='Ch56r'><tfoot id='Ch56r'></tfoot><dl id='Ch56r'><fieldset id='Ch56r'></fieldset></dl></div>
                  1. <legend id='Ch56r'><style id='Ch56r'><dir id='Ch56r'><q id='Ch56r'></q></dir></style></legend>
                    1. <small id='Ch56r'></small><noframes id='Ch56r'>

                        <bdo id='Ch56r'></bdo><ul id='Ch56r'></ul>