2005年06月23日 星期四 07:30
amingsc wrote: > 在wxPython的demo中有post自定义事件的例子,但是对于系统预定义事件我却不知道如何实现,比如: > 我现在要模拟button的click事件,下面的代码需要怎么改进? > evt= wx.CommandEvent(commandType=?,winid=ID_BTN) > wx.PostEvent(win,evt) commandType=wx.wxEVT_COMMAND_BUTTON_CLICKED 看下面的演示代码,点击btn2会产生一个点击btn1的event: import wx class Frame(wx.Frame): def __init__(self, *a, **kw): super(Frame, self).__init__(*a, **kw) self.btn = b = wx.Button(self, -1, 'Click me!') b2 = wx.Button(self, -1, 'Click the above button by code!') sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddMany([b, b2]) self.SetSizerAndFit(sizer) self.Bind(wx.EVT_BUTTON, self.on_btn, b) self.Bind(wx.EVT_BUTTON, self.on_btn2, b2) def on_btn(self, evt): wx.MessageBox('Clicked') def on_btn2(self, evt): new_event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, self.btn.GetId()) wx.PostEvent(self, new_event) if __name__ == '__main__': app = wx.PySimpleApp() frame = Frame(None, -1, 'Test') frame.Show() app.MainLoop() -- Qiangning Hong __________________________________________________________ / Q: Know what the difference between your latest project \ | | | and putting wings on an elephant is? urA: Who knows? The | \ elephant *might* fly, heh, heh... / ---------------------------------------------------------- \ \ ____ /# /_\_ | |/o\o\ | \\_/_/ / |_ | | ||\_ ~| | ||| \/ | |||_ \// | || | ||_ \ \_| o| /\___/ / ||||__ (___)_)
Zeuux © 2025
京ICP备05028076号