我有一个WxWidgets应用程序。我正在使用Python。该应用程序有一个主框架,一个菜单栏,底部有一个状态栏,对于中间的主要内容,我想要一个渐变面板,以提供良好的背景着色效果。我已经完成了这项工作,但现在我想开始将GUI小部件添加到面板中(例如一组静态文本标签和编辑框)。如何将这些添加到面板中,使其显示在面板顶部?在我下面的示例代码中,向面板中添加一个文本字段会导致面板缩小。
谢谢你的帮助。
def createGui(self, parent, title):
wx.Frame.__init__(self, parent, title=title, style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
self.SetBackgroundColour("white")
self.SetSizeHints(800, 640, 800, 600)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.panel = wx.Panel(self, size=(800, 600))
self.sizer.Add(self.panel)
self.panel.Bind(wx.EVT_PAINT, self.on_paint)
self.label1 = wx.StaticText(self, -1, "PV Power" , wx.Point(1, 1))
# This next part is not working, I want to add static text at certain geometric locations to the panel, so I get to see
# the panel with it's background gradient and the text labels on top
#self.panel.AddChild(self.label1)
menubar = wx.MenuBar()
fileMenu = wx.Menu()
fitem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.onQuit, fitem)
# Create a box at the bottom for buttons
self.statusbar = self.CreateStatusBar()
self.statusbar.SetStatusText('Waiting to run')
self.sizer.Add(self.statusbar)
self.SetSizer(self.sizer)
self.SetAutoLayout(1)
self.sizer.Fit(self)
self.Show()
def on_paint(self, event):
dc = wx.PaintDC(self.panel)
x = 0
y = 0
w, h = self.GetSize()
dc.GradientFillLinear((x, y, w, h), 'white', 'light grey')