基于wxpython实现的windows GUI程序实例


Posted in Python onMay 30, 2015

本文实例讲述了基于wxpython实现的windows GUI程序。分享给大家供大家参考。具体如下:

# using a wx.Frame, wx.MenuBar, wx.Menu, wx.Panel, wx.StaticText, wx.Button, 
# and a wx.BoxSizer to show a rudimentary wxPython Windows GUI application
# wxPython package from: http://prdownloads.sourceforge.net/wxpython/
# I downloaded: wxPython2.5-win32-ansi-2.5.3.1-py23.exe
# if you have not already done so install the Python compiler first
# I used Python-2.3.4.exe (the Windows installer package for Python23) 
# from http://www.python.org/2.3.4/
# tested with Python23   vegaseat   24jan2005
import wx
class Frame1(wx.Frame):
  # create a simple windows frame (sometimes called form)
  # pos=(ulcX,ulcY) size=(width,height) in pixels
  def __init__(self, parent, title):
    wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 250))
    # create a menubar at the top of the user frame
    menuBar = wx.MenuBar()
    # create a menu ... 
    menu = wx.Menu()
    # ... add an item to the menu
    # \tAlt-X creates an accelerator for Exit (Alt + x keys)
    # the third parameter is an optional hint that shows up in 
    # the statusbar when the cursor moves across this menu item
    menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit the program")
    # bind the menu event to an event handler, share QuitBtn event
    self.Bind(wx.EVT_MENU, self.OnQuitButton, id=wx.ID_EXIT)
    # put the menu on the menubar
    menuBar.Append(menu, "&File")
    self.SetMenuBar(menuBar)
    # create a status bar at the bottom of the frame
    self.CreateStatusBar()
    # now create a panel (between menubar and statusbar) ...
    panel = wx.Panel(self)
    # ... put some controls on the panel
    text = wx.StaticText(panel, -1, "Hello World!")
    text.SetFont(wx.Font(24, wx.SCRIPT, wx.NORMAL, wx.BOLD))
    text.SetSize(text.GetBestSize())
    quitBtn = wx.Button(panel, -1, "Quit")
    messBtn = wx.Button(panel, -1, "Message")
    # bind the button events to event handlers
    self.Bind(wx.EVT_BUTTON, self.OnQuitButton, quitBtn)
    self.Bind(wx.EVT_BUTTON, self.OnMessButton, messBtn)
    # use a sizer to layout the controls, stacked vertically
    # with a 10 pixel border around each
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(text, 0, wx.ALL, 10)
    sizer.Add(quitBtn, 0, wx.ALL, 10)
    sizer.Add(messBtn, 0, wx.ALL, 10)
    panel.SetSizer(sizer)
    panel.Layout()
  def OnQuitButton(self, evt):
    # event handler for the Quit button click or Exit menu item
    print "See you later alligator! (goes to stdout window)"
    wx.Sleep(1)  # 1 second to look at message
    self.Close()
  def OnMessButton(self, evt):
    # event handler for the Message button click
    self.SetStatusText('101 Different Ways to Spell "Spam"')
class wxPyApp(wx.App):
  def OnInit(self):
    # set the title too
    frame = Frame1(None, "wxPython GUI 2")
    self.SetTopWindow(frame)
    frame.Show(True)
    return True
# get it going ...
app = wxPyApp(redirect=True)
app.MainLoop()

希望本文所述对大家的Python程序设计有所帮助。

Python 相关文章推荐
Python的Flask框架中实现分页功能的教程
Apr 20 Python
Python装饰器使用实例:验证参数合法性
Jun 24 Python
详谈Python2.6和Python3.0中对除法操作的异同
Apr 28 Python
python版飞机大战代码分享
Nov 20 Python
python实现名片管理系统项目
Apr 26 Python
Python3.5 Json与pickle实现数据序列化与反序列化操作示例
Apr 29 Python
利用Django模版生成树状结构实例代码
May 19 Python
python 公共方法汇总解析
Sep 16 Python
python单向链表的基本实现与使用方法【定义、遍历、添加、删除、查找等】
Oct 24 Python
Python笔记之facade模式
Nov 20 Python
Python3的unicode编码转换成中文的问题及解决方案
Dec 10 Python
Python使用Opencv打开笔记本电脑摄像头报错解问题及解决
Jun 21 Python
python简单实现旋转图片的方法
May 30 #Python
Python实现控制台输入密码的方法
May 29 #Python
python删除过期文件的方法
May 29 #Python
Python的Django框架中TEMPLATES项的设置教程
May 29 #Python
编写Python脚本把sqlAlchemy对象转换成dict的教程
May 29 #Python
Python fileinput模块使用实例
May 28 #Python
Python sys.argv用法实例
May 28 #Python
You might like
php 删除无限级目录与文件代码共享
2008/11/22 PHP
php操作xml
2013/10/27 PHP
php下载远程大文件(获取远程文件大小)的实例
2017/06/17 PHP
PHP简单实现解析xml为数组的方法
2018/05/02 PHP
jquery Firefox3.5中操作select的问题
2009/07/10 Javascript
javascript Object与Function使用
2010/01/11 Javascript
javascript学习笔记(五)正则表达式
2011/04/08 Javascript
自己动手制作jquery插件之自动添加删除行的实现
2011/10/13 Javascript
关于JS判断图片是否加载完成且获取图片宽度的方法
2013/04/09 Javascript
jquery ajax同步异步的执行最终解决方案
2013/04/26 Javascript
用jQuery与JSONP轻松解决跨域访问的问题
2014/02/04 Javascript
jQuery设置与获取HTML,文本和值的简单实例
2014/02/26 Javascript
浅析javascript的间隔调用和延时调用
2014/11/12 Javascript
Bootstrap页面布局基础知识全面解析
2016/06/13 Javascript
老生常谈jquery中detach()和remove()的区别
2017/03/02 Javascript
ES6中Array.includes()函数的用法
2017/09/20 Javascript
JavaScript判断变量名是否存在数组中的实例
2017/12/28 Javascript
BootStrap中的模态框(modal,弹出层)功能示例代码
2018/11/02 Javascript
VUE前后端学习tab写法实例
2019/08/06 Javascript
JavaScript ECMA-262-3 深入解析(二):变量对象实例详解
2020/04/25 Javascript
简单讲解Python中的字符串与字符串的输入输出
2016/03/13 Python
Python极简代码实现杨辉三角示例代码
2016/11/15 Python
Python中super函数的用法
2017/11/17 Python
利用python实现简易版的贪吃蛇游戏(面向python小白)
2018/12/30 Python
在Pycharm中对代码进行注释和缩进的方法详解
2019/01/20 Python
Python向excel中写入数据的方法
2019/05/05 Python
python3 反射的四种基本方法解析
2019/08/26 Python
html5使用canvas实现图片下载功能的示例代码
2017/08/26 HTML / CSS
H5混合开发app如何升级的方法
2018/01/10 HTML / CSS
时尚、社区、科技:SEVENSTORE
2019/04/26 全球购物
Craghoppers德国官网:户外和旅行服装
2020/02/14 全球购物
临床医学专业毕业生的自我评价
2013/10/17 职场文书
大学生自我鉴定评语
2014/01/27 职场文书
创建省级文明单位实施方案
2014/02/27 职场文书
2014年公务员思想汇报范文:全心全意为人民服务
2014/03/06 职场文书
Python 视频画质增强
2022/04/28 Python