wxPython:面板Panel的使用

最后更新于:2022-04-01 19:41:12

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() ~~~ 测试: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-08_5757935ece140.png)
';