wxPython窗口的继承机制实例分析

yipeiwu_com5年前Python基础

本文实例讲述了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程序设计有所帮助。

相关文章

pygame游戏之旅 游戏中添加显示文字

pygame游戏之旅 游戏中添加显示文字

本文为大家分享了pygame游戏之旅的第5篇,供大家参考,具体内容如下 在游戏中添加显示文字: 这里自己定义一个crash函数接口: def crash(): message_di...

django数据模型(Model)的字段类型解析

字段类型(Field types) 1、AutoField 它是一个根据 ID 自增长的 IntegerField 字段。通常,你不必直接使用该字段。如果你没在别的字段上指定主 键,Dj...

Python利用matplotlib做图中图及次坐标轴的实例

Python利用matplotlib做图中图及次坐标轴的实例

图中图 准备数据 import matplotlib.pyplot as plt fig = plt.figure() x = [1, 2, 3, 4, 5, 6, 7] y =...

python实现学员管理系统

python实现学员管理系统这个小程序是我刚刚接触python时,导师带着做的第一个小项目。通过这次练习,我学会了很多东西。下面是具体的代码和要求 ''' 学员管理系统1.0版本 1.添...

详解python多线程之间的同步(一)

详解python多线程之间的同步(一)

引言: 线程之间经常需要协同工作,通过某种技术,让一个线程访问某些数据时,其它线程不能访问这些数据,直到该线程完成对数据的操作。这些技术包括临界区(Critical Section),互...