wxPython:退出全屏

发布于 2024-11-18 13:00:29 字数 420 浏览 2 评论 0原文

要以全屏模式显示 wxPython 窗口,您可以使用:

ShowFullScreen(True)

How do you get out of full screen while?我尝试过明显的方法:

ShowFullScreen(True)
sleep(5)
ShowFullScreen(False)

但这不起作用。当我运行脚本时,什么也没有出现。 5 秒后,屏幕左上角会出现一个大约 200x250 的窗口,其中没有任何内容。它似乎也没有任何边界。

如果我将其更改为

showFullScreen(True)

,那么我就会陷入全屏窗口,我必须使用 Alt + F2 -> xkill 才能退出。

To display a wxPython window in full screen mode you use:

ShowFullScreen(True)

How do you get out of full screen though? I've tried the obvious way:

ShowFullScreen(True)
sleep(5)
ShowFullScreen(False)

This doesn't work though. When I run the script, nothing appears. After 5 seconds a window roughly 200x250 appears in the top-left corner of the screen, without anything inside of it. It doesn't appear to have any borders either.

If I change this to

showFullScreen(True)

then I get stuck with a full screen window that I have to use Alt + F2 -> xkill to get out of.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扛刀软妹 2024-11-25 13:00:29

看起来您需要先 Show() 窗口。 (根据 文档,您不必这样做。也许这是一个bug。)我在 Mac OS X 和 Windows 上进行了测试 - 如果您不先调用 Show(),它们都会出现问题。

另请注意,您不应该在主 GUI 线程中休眠。您将挂起 UI。使用 CallLater 是一种潜在的解决方案,如我的示例所示。

工作示例:

import wx

def main():
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, 'Full Screen Test')
    frame.Show()
    frame.ShowFullScreen(True)
    wx.CallLater(5000, frame.ShowFullScreen, False)
    app.MainLoop()

if __name__ == '__main__':
    main()

It looks like you need to Show() the window first. (According to the documentation, you shouldn't have to. Maybe this is a bug.) I tested on Mac OS X and Windows - they both exhibit issues if you don't call Show() first.

Also note that you shouldn't sleep in the main GUI thread. You'll hang the UI. Using CallLater is one potential solution, as shown in my example.

Working example:

import wx

def main():
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, 'Full Screen Test')
    frame.Show()
    frame.ShowFullScreen(True)
    wx.CallLater(5000, frame.ShowFullScreen, False)
    app.MainLoop()

if __name__ == '__main__':
    main()
小梨窩很甜 2024-11-25 13:00:29

ShowFullScreen 的文档如下:
ShowFullScreen(show, style=wx.FULLSCREEN_ALL)

Depending on the value of show parameter the window is either shown full screen or restored to its normal state.

Parameters:

    show (bool)
    style (long): is a bit list containing some or all of the following values, which indicate what elements of the window to hide in full-screen mode:
        wx.FULLSCREEN_NOMENUBAR
        wx.FULLSCREEN_NOTOOLBAR
        wx.FULLSCREEN_NOSTATUSBAR
        wx.FULLSCREEN_NOBORDER
        wx.FULLSCREEN_NOCAPTION
        wx.FULLSCREEN_ALL (all of the above)

因此,将全屏切换事件放入菜单中并使用以下命令启动全屏模式:
self.window.ShowFullScreen(True, style=(wx.FULLSCREEN_NOTOOLBAR | wx.FULLSCREEN_NOSTATUSBAR |wx.FULLSCREEN_NOBORDER |wx.FULLSCREEN_NOCAPTION))

注意,我省略了wx.FULLSCREEN_NOMENUBAR,这样你仍然会能够访问菜单以再次关闭全屏模式。

The documentation for ShowFullScreen reads:
ShowFullScreen(show, style=wx.FULLSCREEN_ALL)

Depending on the value of show parameter the window is either shown full screen or restored to its normal state.

Parameters:

    show (bool)
    style (long): is a bit list containing some or all of the following values, which indicate what elements of the window to hide in full-screen mode:
        wx.FULLSCREEN_NOMENUBAR
        wx.FULLSCREEN_NOTOOLBAR
        wx.FULLSCREEN_NOSTATUSBAR
        wx.FULLSCREEN_NOBORDER
        wx.FULLSCREEN_NOCAPTION
        wx.FULLSCREEN_ALL (all of the above)

So put your Full Screen toggle event/s in a Menu and start full screen mode with:
self.window.ShowFullScreen(True, style=(wx.FULLSCREEN_NOTOOLBAR | wx.FULLSCREEN_NOSTATUSBAR |wx.FULLSCREEN_NOBORDER |wx.FULLSCREEN_NOCAPTION))

Note that I omitted wx.FULLSCREEN_NOMENUBAR, in this way you will still be able to access the menu to turn full screen mode off again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文