wxpython 框架在顶部

发布于 2024-11-18 23:13:34 字数 364 浏览 4 评论 0原文

我如何创建一个位于所有其他窗口之上的框架?另外,我不希望将框架创建为顶部窗口,我希望用户有一个可以单击的按钮,以便框架变为顶部模式,如果再次单击它,它就会变成普通框架!

我尝试使用

frame= wx.Frame.__init__(self, None, -1, 'Hello',wx.DefaultPosition,(400,500),style=  wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)

self.SetTopWindow(self.frame)

,但收到错误消息,指出 self.SetTopWindow 不存在。

谢谢

how can i create a frame that is on top of all the other windows ? also i don't want the frame to be created as an on top window, i want the user to have a button that can be clicked so the frame becomes in on top mode and if it is clicked again then it becomes a normal frame !

i tried using

frame= wx.Frame.__init__(self, None, -1, 'Hello',wx.DefaultPosition,(400,500),style=  wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)

self.SetTopWindow(self.frame)

but i got an error saying that self.SetTopWindow does not exist.

Thanks

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

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

发布评论

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

评论(5

陪你搞怪i 2024-11-25 23:13:34

这是一个老问题,但仅供记录使用:

self.SetWindowStyle(wx.STAY_ON_TOP)

It's an old question but for the record use:

self.SetWindowStyle(wx.STAY_ON_TOP)
风情万种。 2024-11-25 23:13:34

您肯定想要 wx.STAY_ON_TOP 样式,但我不知道在创建框架后是否可以实际应用该样式。请注意,如果您在 init 中创建框架时使用该样式,您将只能获得该样式,并且不会有标题栏或按钮。所以你通常应该这样做:

wx.Frame.__init__(self, None, style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP)

You definitely want the wx.STAY_ON_TOP style, but I don't know if you can actually apply that style after the frame is already created. Note that if you use that style when creating the frame in its init, you will only get that style and you won't have the title bar or buttons. So you should normally do it like this:

wx.Frame.__init__(self, None, style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP)

好倦 2024-11-25 23:13:34

我认为你想要的是 Z 顺序。谷歌搜索 wxpython window z 得到这个: http://wxpython-users.1045709.n5.nabble.com/Bringing-a-Window-to-the-Top-td2289667.html

http://docs.wxwidgets.org/trunk/classwx_window.html#54808c933f22a891c5db646f6209fa4d 有这样的说法:

virtual void wxWindow::Raise    (        )      [virtual]

Raises the window to the top of the window hierarchy (Z-order).

Notice that this function only requests the window manager to raise this window to the top of Z-order. Depending on its configuration, the window manager may raise the window, not do it at all or indicate that a window requested to be raised in some other way, e.g. by flashing its icon if it is minimized.

Remarks:
    This function only works for wxTopLevelWindow-derived classes.

I think what you want is Z-order. Googling wxpython window z got this: http://wxpython-users.1045709.n5.nabble.com/Bringing-a-Window-to-the-Top-td2289667.html

http://docs.wxwidgets.org/trunk/classwx_window.html#54808c933f22a891c5db646f6209fa4d has this to say:

virtual void wxWindow::Raise    (        )      [virtual]

Raises the window to the top of the window hierarchy (Z-order).

Notice that this function only requests the window manager to raise this window to the top of Z-order. Depending on its configuration, the window manager may raise the window, not do it at all or indicate that a window requested to be raised in some other way, e.g. by flashing its icon if it is minimized.

Remarks:
    This function only works for wxTopLevelWindow-derived classes.
唠甜嗑 2024-11-25 23:13:34

尝试创建不带 wx.STAY_ON_TOP 样式的 UI,然后在类中使用以下内容在样式之间切换 - 确保在初始化 UI 时调用 set_style。

def set_style( self, event = None ):
    self.old_style = self.GetWindowStyle()

def stay_on_top( self, event=None ):
    self.SetWindowStyle(self.old_style | wx.STAY_ON_TOP)

def cancel_on_top( self, event = None ):
    self.SetWindowStyle(self.old_style)

或者如果您使用的是复选框

def stay_on_top( self, event = None ):
    if self.c_ontop.IsChecked():
        self.SetWindowStyle(self.old_style | wx.STAY_ON_TOP)
    else:
        self.SetWindowStyle(self.old_style)

try creating your UI with no wx.STAY_ON_TOP style, then use the following in your class to switch between styles - make sure to call set_style when initialising your UI.

def set_style( self, event = None ):
    self.old_style = self.GetWindowStyle()

def stay_on_top( self, event=None ):
    self.SetWindowStyle(self.old_style | wx.STAY_ON_TOP)

def cancel_on_top( self, event = None ):
    self.SetWindowStyle(self.old_style)

or if you are using a checkbox

def stay_on_top( self, event = None ):
    if self.c_ontop.IsChecked():
        self.SetWindowStyle(self.old_style | wx.STAY_ON_TOP)
    else:
        self.SetWindowStyle(self.old_style)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文