wxpython panel fullscreen?

前端 未结 3 975
暖寄归人
暖寄归人 2021-01-28 04:55

I am trying to make my top_panel of my program go into fullscreen only, i hope to have a button which will do this, the issue i am faced with is i dont know how to make the pane

3条回答
  •  野性不改
    2021-01-28 05:13

    Using Mike Driscoll's example code, there is a way of faking full screen for a panel, when more than one panel is being used. It's a bit of a hack at the moment but it should give you the gist of it.
    Use SetMinSize and SendSizeEvent.
    Click on a coloured panel for focus and then press F1,F2 or F3 to swap the panels in and out of "full screen" or revert to equal sizes.

    import wx
    
    class MyPanel(wx.Panel):
        """"""
    
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent)
    
            self.Bind(wx.EVT_KEY_DOWN, self.onKey)
    
        def onKey(self, event):
            """
            Check for ESC key press and exit is ESC is pressed
            F1 panel 1 is full screen
            F2 panel 2 is full screen
            F3 panels revert to equal sizes
            """
            key_code = event.GetKeyCode()
            parent = self.GetParent()
            width, height = wx.GetDisplaySize()
            if key_code == wx.WXK_ESCAPE:
                self.GetParent().Close()
            elif key_code == wx.WXK_F1: 
                parent.panel1.SetMinSize((1,1))
                parent.panel2.SetMinSize((width,height))
                parent.SendSizeEvent()
                parent.Layout()
                parent.Fit()
            elif key_code == wx.WXK_F2: 
                parent.panel2.SetMinSize((1,1))
                parent.panel1.SetMinSize((width,height))
                parent.SendSizeEvent()
                parent.Layout()
                parent.Fit()
            elif key_code == wx.WXK_F3: 
                parent.panel2.SetMinSize((120,70))
                parent.panel1.SetMinSize((120,70))
                parent.SendSizeEvent()
                parent.Layout()
                parent.Fit()
            else:
                event.Skip()
    
    class MyFrame(wx.Frame):
        """"""
    
        def __init__(self):
            """Constructor"""
            wx.Frame.__init__(self, None, title="Test FullScreen")
            self.panel1 = MyPanel(self)
            self.panel2 = MyPanel(self)
            self.panel1.SetBackgroundColour(wx.GREEN)
            self.panel2.SetBackgroundColour(wx.BLUE)
            vbox = wx.BoxSizer(wx.VERTICAL)
            vbox.Add(self.panel1)
            vbox.Add(self.panel2)
            self.SetSizer(vbox)
            self.Show()
    
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MyFrame()
        app.MainLoop()
    

    Note: for your case you will not want to really go to full screen, as you will probably need to still access some control buttons, so just deduct the amount you need from the full screen size.

提交回复
热议问题