【发布时间】:2017-01-18 12:48:55
【问题描述】:
我是 wxPython 的新手,在为框架和窗口(小部件)设置给定大小时发现了一些问题。我已将问题隔离到我尝试创建 250x250 像素的帧的最简单情况。
运行代码,我得到一个实际大小为 295 宽 x 307 高的窗口(考虑到 Windows 的顶部窗口栏)
我在 Windows 10 中使用 Python 2.7。
我错过了什么?
#!/bin/env python
import wx
# App Class
class MyAppTest7(wx.App):
def OnInit(self):
frame = AppFrame(title = u'Hello World', pos=(50, 60), size=(250, 250))
frame.Show()
self.SetTopWindow(frame)
return True
# AppFrame
class AppFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, parent=None, id=-1, title=title, pos=pos, size=size)
if __name__ == '__main__':
app = MyAppTest7(False)
app.MainLoop()
进一步显示问题的附加测试:
#!/bin/env python
import wx
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title="The Main Frame")
self.SetTopWindow(self.frame)
self.frame.Show(True)
return True
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=(400,100), style=wx.DEFAULT_FRAME_STYLE, name="MyFrame"):
super(MyFrame, self).__init__(parent, id, title, pos, size, style, name)
self.panel = wx.Panel(self)
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
结果:
如您所见,显示的窗口(框架)有 482 像素(-参见 Paint 的底部栏-),而不是预期的 400。
【问题讨论】:
-
Frame的尺寸是怎么测量的?
-
我在 Windows 10 中使用 Alt + PrintScreen 键截取屏幕截图。然后我只是在 Paint 中测量宽度。
-
取你的屏幕尺寸并使其成为框架的宽度,然后使用
print self.frame.GetSize()看看你会得到什么。 -
我将宽度设置为 1920 像素。我得到了 1911 的实际宽度,我从 print self.frame.GetSize() 得到了 1552
-
我的文本比例设置为 125%(在 15.6" 笔记本电脑屏幕上为 1920x1080)。如果我将文本比例设置为 100%,那么我得到的实际宽度为 1906 像素,而 wxPython 从打印中报告 1932 self.frame.GetSize()。这很奇怪,似乎 wxPython 无法在我的特定笔记本电脑(Windows 10)中获得正确大小的东西
标签: python python-2.7 wxpython wxwidgets