wxPython 将窗口设置在屏幕中央
在这篇文章中,我们将学习如何将窗口显示在屏幕中央。我们可以通过使用wx.Frame模块中的Centre()函数来做到这一点。
语法:
wx.Frame.Centre(self, direction = wx.BOTH)
参数:
参数 | 输入类型 | 说明 |
---|---|---|
direction | int | 该参数可以是wx.HORIZONTAL、wx.VERTICAL或wx.BOTH。 |
例子 #1:
# 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:
# 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()
输出: