基于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 相关文章推荐
Windows下Python使用Pandas模块操作Excel文件的教程
May 31 Python
Python搭建HTTP服务器和FTP服务器
Mar 09 Python
Python竟能画这么漂亮的花,帅呆了(代码分享)
Nov 15 Python
python实现外卖信息管理系统
Jan 11 Python
Python 访问限制 private public的详细介绍
Oct 16 Python
华为校园招聘上机笔试题 扑克牌大小(python)
Apr 22 Python
python实现图片九宫格分割
Mar 07 Python
使用Python生成200个激活码的实现方法
Nov 22 Python
Python读取csv文件实例解析
Dec 30 Python
python重要函数eval多种用法解析
Jan 14 Python
Python之关于类变量的两种赋值区别详解
Mar 12 Python
Python中的 enumerate和zip详情
May 30 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对称加密函数实现数据的加密解密
2016/10/27 PHP
php自定义时间转换函数示例
2016/12/07 PHP
Laravel中获取路由参数Route Parameters的五种方法示例
2017/09/29 PHP
PHP过滤器 filter_has_var() 函数用法实例分析
2020/04/23 PHP
JavaScript中String和StringBuffer的速度之争
2010/04/01 Javascript
客户端验证用户名和密码的方法详解
2016/06/16 Javascript
javascript 常用验证函数总结
2016/06/28 Javascript
js enter键激发事件实例代码
2016/08/17 Javascript
jquery validate表单验证插件
2016/09/06 Javascript
如何给ss bash 写一个 WEB 端查看流量的页面
2017/03/23 Javascript
详解Chai.js断言库API中文文档
2018/01/31 Javascript
原生JS实现多个小球碰撞反弹效果示例
2018/01/31 Javascript
基于vue.js中事件修饰符.self的用法(详解)
2018/02/23 Javascript
微信小程序中上传图片并进行压缩的实现代码
2018/08/28 Javascript
创建Vue项目以及引入Iview的方法示例
2018/12/03 Javascript
Node.js console控制台简单用法分析
2019/01/04 Javascript
详解element-ui日期时间选择器的日期格式化问题
2019/04/08 Javascript
JS使用new操作符创建对象的方法分析
2019/05/30 Javascript
vue-cli3 热更新配置操作
2020/09/18 Javascript
python读写二进制文件的方法
2015/05/09 Python
基于python select.select模块通信的实例讲解
2017/09/21 Python
Python GUI编程完整示例
2019/04/04 Python
Django REST framework 分页的实现代码
2019/06/19 Python
Python定时任务随机时间执行的实现方法
2019/08/14 Python
Python模块_PyLibTiff读取tif文件的实例
2020/01/13 Python
pandas创建DataFrame的7种方法小结
2020/06/14 Python
python在linux环境下安装skimage的示例代码
2020/10/14 Python
CSS3移动端vw+rem不依赖JS实现响应式布局的方法
2019/01/23 HTML / CSS
加拿大最大的体育用品、鞋类和服装零售商:Sport Chek
2018/11/29 全球购物
店面销售职位的职责
2014/03/09 职场文书
小学教师培训方案
2014/06/09 职场文书
2015年社区卫生工作总结
2015/04/21 职场文书
听课评课活动心得体会
2016/01/15 职场文书
php 原生分页
2021/04/01 PHP
图文详解matlab原始处理图像几何变换
2021/07/09 Python
Docker部署Mysql8的实现步骤
2022/07/07 Servers