AddPendingEvent有n个

2024-10-01 04:47:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用AddPendingEvent发送事件。但是,在调用AddPendingEvent之后什么也不会发生。下面是一个示例,其中一个按钮将向帧发送wx.CloseEvent。你知道吗

import wx

class MainFrame(wx.Frame):
    def __init__(self):
        super(wx.Frame, self).__init__(None, wx.ID_ANY, 'Test')

        self.button = wx.Button(self, wx.ID_ANY, 'Close', self.GetClientSize()/2)
        self.button.Bind(wx.EVT_BUTTON, self.OnButton)

        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.Show()

    def OnButton(self, event: wx.CommandEvent):
        self.AddPendingEvent(wx.CloseEvent())

    def OnClose(self, event: wx.CloseEvent):
        self.Destroy()

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame()
    app.MainLoop()

我也试过QueueEventwx.PostEvent,结果是一样的。你知道吗


Tags: selfidinitbinddefanybuttonframe
1条回答
网友
1楼 · 发布于 2024-10-01 04:47:26

您应该按PyCommandEvent创建一个类型为wx.EVT\u关闭例如:

self.AddPendingEvent(wx.PyCommandEvent(wx.EVT_CLOSE.typeId, self.GetId()))

相关问题 更多 >