开发者

Bind to same function in Python

开发者 https://www.devze.com 2023-02-17 21:51 出处:网络
I need to use two events to send a message from child frame to main frame and close the child frame (by using pubsub). One of the events is the click event of a \"Cancel\" button on the child frame an

I need to use two events to send a message from child frame to main frame and close the child frame (by using pubsub). One of the events is the click event of a "Cancel" button on the child frame and the other one is the close event of the child frame. So I use a common "OnClose" function for both of them. Here is my related code:

self.Bind(wx.EVT_BUTTON, self.OnClose, id=cancel.GetId())

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

def OnClose(self, event):
    self.Close()
    Pubsub().sendMessage(("show.mainframe"),"")`

Every time I close my child frame, it actuall开发者_运维知识库y doesnt close and when I try to reopen the child frame from the main frame, a new child frame is generated on top of the previous one. Actually I solved this problem by using the code inside the destructor function (del). But I am curious why in the first method it doesnt work.

Thanks in advance.


Try reversing the order of your calls in your OnClose method. Put the pubsub call first and the Close call last. Or just use Destroy() at the end instead of Close().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号