wxPython:面板Panel的使用

 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()

 

测试:

  

posted @ 2012-07-05 23:22  Socrates  阅读(17435)  评论(0编辑  收藏  举报