如何在桌面中间显示wxpython顶部框架?

2024-04-28 20:12:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使我的GUI程序顶部框架垂直和水平对齐。

wx.Frame.__init__(self, parent=None, id= -1, title="Test Frame", pos=(-1, -1), size=(1280, 770), style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)

我应该做什么(除了计算找到绝对位置)来pos=(-1, -1)使它显示在中间(不管是800*600还是1280*800等等),或者还需要一些其他属性设置?


Tags: postestself程序box框架noneid
2条回答
w = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)
h = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)

pos=(w/2, h/2)

这给了你屏幕的中心。

现在,假设您有一个800x600大小的应用程序:

APPWIDTH = 800
APPHEIGHT = 600

w = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)
h = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)

# Centre of the screen
x = w / 2
y = h / 2

# Minus application offset
x -= (APPWIDTH / 2)
y -= (APPHEIGHT / 2)

pos=(x, y)

简单使用

self.Center()

在类__init__()而不是pos=(-1,-1)中。

相关问题 更多 >