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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

500行Python代码打造刷脸考勤系统

500行Python代码打造刷脸考勤系统

需求分析 “员工刷脸考勤”系统,采用Python语言开发,可以通过摄像头添加员工面部信息,这里就涉及到两个具体的个问题,一个是应该以什么样的数据来标识每一个员工的面部信息,二是持久化地保...

python新手经常遇到的17个错误分析

1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 “SyntaxError :invalid syntax”)...

python 基于dlib库的人脸检测的实现

python 基于dlib库的人脸检测的实现

本周暂时比较清闲,可以保持每日一更的速度。 国外身份证项目新增需求,检测出身份证正面的人脸。最开始考虑mobilenet-ssd,经同事提醒,有现成的人脸库dlib,那就用传统方法尝试一...

python和shell获取文本内容的方法

这两天搞脚本,花费不少时间。 Python和Shell都可以获取文本内容,网上许多资料介绍的都不具体。简单的使用Python和Shell写了脚本。 做一些笔记沉淀一下。 1、Python...

python实现对指定输入的字符串逆序输出的6种方法

对于一个给定的字符串,逆序输出,这个任务对于python来说是一种很简单的操作,毕竟强大的列表和字符串处理的一些列函数足以应付这些问题 了,今天总结了一下python中对于字符串的逆序输...