【问题标题】:Make a wx.Panel have a specific width and height inside a wx.Frame (wxPython - wxWidgets)使 wx.Panel 在 wx.Frame 中具有特定的宽度和高度(wxPython - wxWidgets)
【发布时间】:2016-09-10 13:08:14
【问题描述】:

我正在尝试在 wx.Frame 中获取给定大小的 wx.Panel。

我试过下面的代码,明确指定wx.Panel的大小,但没有成功。

当我运行应用程序时,我发现 wx.Panel 的宽度大于 100 像素。

Actual wx.Panel width is about 125pixels instead of 100

有人可以帮我找出这里没有正确使用的东西吗?

#!/bin/env python
import wx

# App Class
class MyAppTest6(wx.App):

    def OnInit(self):

        frame = AppFrame(title = u'Hello World', pos=(50, 60), size=(150, 250))
        frame.Show()
        #self.SetTopWindow(frame)
        return True

# Form Panel, 300 pixels Panel
class Form(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(100, 100))

        self.SetBackgroundColour('RED')
        self.SetInitialSize(
            (100,100)
        )
        self.SetSize(
            (100,100)
        )

# AppFrame
class AppFrame(wx.Frame):
    def __init__(self, title, pos, size):
        wx.Frame.__init__(self, None, -1, title, pos, size)

        # Define color
        self.SetBackgroundColour('LIGHTGREY')

        # Add elements
        self.form = Form(self)

        # Layout
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.AddStretchSpacer()
        sizer.Add(self.form, 0, wx.CENTER)
        sizer.AddStretchSpacer()
        self.SetSizer(sizer)


if __name__ == '__main__':
        app = MyAppTest6(False)
        app.MainLoop()

【问题讨论】:

    标签: python-2.7 wxpython wxwidgets


    【解决方案1】:

    正如您在this 问题中看到的那样,您可以在调用 app.MainLoop() 之前添加它:

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

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 2016-01-11
      相关资源
      最近更新 更多