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.CA开发者_开发问答PTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)
self.SetTopWindow(self.frame)
but i got an error saying that self.SetTopWindow does not exist.
Thanks
I think you might want to look at something like
self.ToggleWindowStyle(wx.STAY_ON_TOP)
http://docs.wxwidgets.org/stable/wx_wxwindow.html#wxwindowtogglewindowstyle and http://docs.wxwidgets.org/stable/wx_wxframe.html#wxframe
It's an old question but for the record use:
self.SetWindowStyle(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)
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.
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)
精彩评论