lang:python:wxpython:event
文書の過去の版を表示しています。
wxpython の event と Bind
evnt と Bind
よくある例:
button1 = wx.Button(self, wx.ID_ANY, 'button1') button1.Bind(wx.EVT_BUTTON, self.onButton1) button2 = wx.Button(self, wx.ID_ANY, 'button2') button2.Bind(wx.EVT_BUTTON, self.onButton2) def onButton1(self, event) : print ("push Button1") def onButton2(self, event) : print ("push Button2")
別の例
widgets は、name を与えることにより、区別できる。こちらのほうが個人的には、好みである。
button1 = wx.Button(self, wx.ID_ANY, 'button', name='button1') button2 = wx.Button(self, wx.ID_ANY, 'button', name='button2') # ボタンが押された event を panel などに Bindする。 self.Bind(wx.EVT_BUTTON, self.onButton) def onButton(self, event) : buttonObject = event.GetEventObject() print ("push: ", buttonObject.GetName())
例
- buttonEvent.py
import os import sys import wx class TopPanel(wx.Panel) : def __init__(self, parent, *args, **kwargs) : wx.Panel.__init__(self, parent, wx.ID_ANY) button1 = wx.Button(self, wx.ID_ANY, 'button1', name='button1') button2 = wx.Button(self, wx.ID_ANY, 'button2', name='button2') layout = wx.BoxSizer(wx.VERTICAL) layout.Add(button1, 1, flag=wx.EXPAND) layout.Add(button2, 1, flag=wx.EXPAND) self.SetSizer(layout) self.Bind(wx.EVT_BUTTON, self.onButton) def onButton(self, event) : buttonObject = event.GetEventObject() print ("push: ", buttonObject.GetName()) class MainFrame(wx.Frame) : def __init__(self) : super().__init__(None, title="exFrame") topPanel = TopPanel(self) layout = wx.BoxSizer(wx.VERTICAL) layout.Add(topPanel, 1, flag=wx.EXPAND) self.SetSizer(layout) self.SetSize(500,500) self.SetMinSize((100, 100)) self.Center(wx.BOTH) self.Show() def main() : app = wx.App() MainFrame() app.MainLoop() return if __name__ == '__main__' : main()
lang/python/wxpython/event.1755424140.txt.gz · 最終更新: by editor