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

 

測試:

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM