wxpython panel fullscreen?

北慕城南 提交于 2020-12-27 06:14:36

问题


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 panel go into fullscreen it self without forcing the whole frame to go into fullscreen using ShowFullscreen(true)

i hope you can help me

class top_panel(wx.Panel):

def __init__(self, parent):
    wx.Panel.__init__(self, parent=parent, size=(400,175))
    self.SetBackgroundColour('BLACK')
    self.ofullscreen = wx.Button(self, -1, "Fullscreen", (10,30))
    self.ofullscreen.Bind(wx.EVT_BUTTON, self.onfullscreen, self.ofullscreen)
    self.gbs = wx.GridBagSizer(2,2)
    self.Bind(wx.EVT_KEY_DOWN, self.onKey)
    wx.Frame.ShowFullScreen(True)
#----------------------------------------------------------------------
def onKey(self, event):
    """
    Check for ESC key press and exit is ESC is pressed
    """
    key_code = event.GetKeyCode()
    if key_code == wx.WXK_ESCAPE:
        self.GetParent().Close()
    else:
        event.Skip()   

def onfullscreen(self):
    print "hola"
    #self.fullscreen?????

回答1:


I have written about this subject on my blog. Here's an example:

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
        """
        key_code = event.GetKeyCode()
        if key_code == wx.WXK_ESCAPE:
            self.GetParent().Close()
        else:
            event.Skip()


class MyFrame(wx.Frame):
    """"""

    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Test FullScreen")
        panel = MyPanel(self)
        self.ShowFullScreen(True)


if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

I have noticed that this code doesn't seem to work with Macs.




回答2:


You can't show a child window, such as a panel, full screen. Only top level frames can be shown full screen but, of course, this shouldn't be a problem at all because absolutely nothing prevents you from creating a frame containing just the panel and then showing this frame full screen is completely equivalent to showing the panel full screen.




回答3:


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.



来源:https://stackoverflow.com/questions/40974292/wxpython-panel-fullscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!