简体   繁体   中英

WxPython custom popup window

I am trying to make a custom window that acts like a popup window and closes as it loses its focus (click outside of popup).

I have a frame with several clickable images. If you click one of the images a frame appears. This frame is a base class and its contents (text controls, grids, buttons etc) are replaced depending on what image you clicked. My problem is where and what event I should capture.

I will try to simplify with sample/pseudo code.

class MainFrame(MainFrameDefinition):
    # unimportant code
    custom_frame_holder = CustomFrame()
    for child_panel in self.lots_of_panels:
        # add a panel to a map and set
        custom_frame_holder.panel = child_panel

class CustomFrame(wx.Frame):
    def __init__(self, parent):
        # unimportant code
        self.panel = # a panel that changes
        self.Bind(wx.EVT_KILL_FOCUS, self.lost_focus)

    def lost_focus(self, event):
        self.Hide()

So what seems to be the officer problem? Well as soon as I click on a control in the CustomFrame, the frame loses its focus and the window will hide. I have tried to capture EVT_CHILD_FOCUS and then set the focus back to the frame, but then, since the frame has the focus I am unable to write in say a text control.

I have looked at the wxPopup and wxTransientPopup, but they apparently have a bug that doesn't allow radio buttons, which makes them useless to me.

Let me know if I make no sense and I will try to explain better.

Use wxEVT_ACTIVATE for this purpose (probably wx.EVT_ACTIVATE in wxPython ).

I think the radio button issue in popup windows was fixed in the trunk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM