设置 wx.Frame 大小 (wxPython - wxWidgets) [英] Set wx.Frame size (wxPython - wxWidgets)

查看:39
本文介绍了设置 wx.Frame 大小 (wxPython - wxWidgets)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 wxPython 的新手,在为框架和窗口(小部件)设置给定大小时发现了一些问题.我已将问题隔离到最简单的情况,即我尝试创建 250x250 像素的帧.

运行代码,我得到一个实际大小为 295 宽 x 307 高的窗口(考虑到 Windows 的顶部窗口栏)

我在 Windows 10 中使用 Python 2.7.

我错过了什么?

#!/bin/env python进口 wx# 应用类类 MyAppTest7(wx.App):def OnInit(self):frame = AppFrame(title = u'Hello World', pos=(50, 60), size=(250, 250))frame.Show()self.SetTopWindow(frame)返回真# 应用框架类 AppFrame(wx.Frame):def __init__(self, title, pos, size):wx.Frame.__init__(self, parent=None, id=-1, title=title, pos=pos, size=size)如果 __name__ == '__main__':app = MyAppTest7(False)app.MainLoop()

进一步显示问题的附加测试:

#!/bin/env python进口 wx类 MyApp(wx.App):def OnInit(self):self.frame = MyFrame(None, title="主框架")self.SetTopWindow(self.frame)self.frame.Show(True)返回真类 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)如果 __name__ == "__main__":应用程序 = 我的应用程序(假)app.MainLoop()

结果:

如您所见,显示的窗口(框架)有 482 像素(-请参阅 Paint 的底部栏-)而不是预期的 400.

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.

Running the code I get a window of an actual size of 295 width by 307 height (taking into consideration the Windows´s top window bar)

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

解决方案

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:

这篇关于设置 wx.Frame 大小 (wxPython - wxWidgets)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆