Wednesday, September 25, 2024
Google search engine
HomeLanguageswxPython – Set window in center of screen

wxPython – Set window in center of screen

In this article we are going to learn that, how can we show window in the center of the screen. We can do this by using a Centre() function in wx.Frame module. 
 

Syntax: 
 

wx.Frame.Centre(self, direction = wx.BOTH)

Parameters: 
 

Parameter Input Type Description
direction int The parameter may be wx.HORIZONTAL, wx.VERTICAL or wx.BOTH.

 

Example #1: 
 

Python3




# import wxPython
import wx
 
class Example(wx.Frame):
 
    def __init__(self, parent, title):
 
        super(Example, self).__init__(parent, title = title,
                                           size =(300, 200))
 
        # Centre frame using Centre() function
        self.Centre()
 
def main():
 
    app = wx.App()
    ex = Example(None, title ='Centering')
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output: 
 

Example #2: 
 

Python3




# import wxPython
import wx
 
class Example(wx.Frame):
 
    def __init__(self, parent, title):
        super(Example, self).__init__(parent, title = title,
                                          size =(300, 200))
 
        # Centre frame using Centre() function
        self.Centre(direction = wx.VERTICAL)
 
 
def main():
 
    app = wx.App()
    ex = Example(None, title ='Centering')
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output: 
 

 

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments