Set wx.Frame size (wxPython - wxWidgets)

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

I am new to wxPython and I am finding some issues while seting a given size for both frames and windows (widgets). I have isolated the issue to the simplest case where I try to create a Frame of 250x250 pixels.

I am using Python 2.7 in Windows 10.

What am I missing?

#!/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() 

An addtional test to further show issue:

#!/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() 

And the result:

As you can see displayed window (frame) has 482 pixels (-see Paint's bottom bar-) instead of the expected 400.

Window size measured in pixels

回答1:

Add this before your call to app.MainLoop():

import wx.lib.inspection wx.lib.inspection.InspectionTool().Show() 

That will let you easily see the actual size (and other info) for each widget in the application, like this:



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!