📜  wxPython - 在屏幕中心设置窗口

📅  最后修改于: 2022-05-13 01:54:34.291000             🧑  作者: Mango

wxPython - 在屏幕中心设置窗口

在本文中,我们将学习如何在屏幕中央显示窗口。我们可以通过使用 wx.Frame 模块中的 Centre()函数来做到这一点。

示例 #1:

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


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()


输出:

示例 #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()

输出: