Panel是窗口的容器,通常其大小與Frame一樣,在其上放置各種控件,這樣可將窗口內容與工具欄及狀態欄區分開,能過TAB鍵可遍歷Panel中的元素,直接看個例子:
#!/usr/bin/env python # -*- coding: utf-8 -*- import wx class MyFrame(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, u'測試面板Panel', size = (600, 300)) #創建面板 panel = wx.Panel(self) #在Panel上添加Button button = wx.Button(panel, label = u'關閉', pos = (150, 60), size = (100, 60)) #綁定單擊事件 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button) def OnCloseMe(self, event): self.Close(True) if __name__ == '__main__': app = wx.PySimpleApp() frame = MyFrame(parent = None, id = -1) frame.Show() app.MainLoop()
測試:

