本文實例講述了wxPython窗口的繼承機制,分享給大家供大家參考。具體分析如下:
示例代碼如下:
import wx class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, title = "My Main Frame jb51.net") self.SetTopWindow(self.frame) self.frame.Show() return True class MyFrame(wx.Frame): def __init__(self, parent, id=wx.ID_ANY, title=""): super(MyFrame, self).__init__(parent, id , title) # Attributes self.panel = wx.Panel(self) self.panel.SetBackgroundColour(wx.BLACK)#設置面板的背景色為黑色,wx.BLACK為大寫,在此犯過錯 self.button = wx.Button(self.panel, label="push me", pos=(50, 50))#一個按鈕的屬性,按鈕的父窗口為panel if __name__ == "__main__": app = MyApp() app.MainLoop()
其中的wx.Button函數介紹如下:
wx.Button (wxWindow *parent, wxWindowID id, const wxString &label=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxButtonNameStr)
Constructor, creating and showing a button.
三層窗口框架:
1. frame或dialog
2. panel或notebooks...
3. controls
最后,來張效果圖:
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答