基于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之传说中的函数编写条规
Oct 11 Python
Python操作SQLite数据库的方法详解
Jun 16 Python
Python中的TCP socket写法示例
May 11 Python
Python+OpenCV实现图像融合的原理及代码
Dec 03 Python
Opencv实现抠图背景图替换功能
May 21 Python
python实现切割url得到域名、协议、主机名等各个字段的例子
Jul 25 Python
pytorch 使用单个GPU与多个GPU进行训练与测试的方法
Aug 19 Python
通过实例简单了解Python中yield的作用
Dec 11 Python
python实现图片横向和纵向拼接
Mar 05 Python
tensorflow模型转ncnn的操作方式
May 25 Python
Django实现任意文件上传(最简单的方法)
Jun 03 Python
详解Python之Scrapy爬虫教程NBA球员数据存放到Mysql数据库
Jan 24 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面向对象全攻略 (十六) 对象的串行化
2009/09/30 PHP
php变量作用域的深入解析
2013/06/03 PHP
利用php+mcDropdown实现文件路径可在下拉框选择
2013/08/07 PHP
PHP把MSSQL数据导入到MYSQL的方法
2014/12/27 PHP
优化WordPress的Google字体以加速国内服务器上的运行
2015/11/24 PHP
PHP数组生成XML格式数据的封装类实例
2016/11/10 PHP
Js 回车换行处理的办法及replace方法应用
2013/01/24 Javascript
jquery easyui combobox模糊过滤(示例代码)
2013/11/30 Javascript
jQuery实现字符串按指定长度加入特定内容的方法
2015/03/11 Javascript
angularjs实现下拉列表的选中事件示例
2017/03/03 Javascript
Angular 项目实现国际化的方法
2018/01/08 Javascript
webpack4.0打包优化策略整理小结
2018/03/30 Javascript
vuejs实现ready函数加载完之后执行某个函数的方法
2018/08/31 Javascript
layer.confirm()右边按钮实现href的例子
2019/09/27 Javascript
[02:40]2014DOTA2 国际邀请赛中国区预选赛 四大豪门抵达华西村
2014/05/23 DOTA
[47:10]完美世界DOTA2联赛PWL S3 LBZS vs Rebirth 第二场 12.16
2020/12/18 DOTA
Python调用C/C++动态链接库的方法详解
2014/07/22 Python
Python实现将目录中TXT合并成一个大TXT文件的方法
2015/07/15 Python
python控制windows剪贴板,向剪贴板中写入图片的实例
2018/05/31 Python
Sanic框架路由用法实例分析
2018/07/16 Python
pandas通过索引进行排序的示例
2018/11/16 Python
Python设计模式之工厂方法模式实例详解
2019/01/18 Python
Python 20行简单实现有道在线翻译的详解
2019/05/15 Python
PyTorch中torch.tensor与torch.Tensor的区别详解
2020/05/18 Python
Python正则表达式高级使用方法汇总
2020/06/18 Python
python如何实现word批量转HTML
2020/09/30 Python
python中str内置函数用法总结
2020/12/27 Python
PatPat德国:妈妈的每日优惠
2019/10/02 全球购物
ktv收银员岗位职责
2013/12/16 职场文书
记者岗位职责
2014/01/06 职场文书
优秀班集体先进事迹材料
2014/05/28 职场文书
学雷锋宣传标语
2014/06/25 职场文书
ktv周年庆活动方案
2014/08/18 职场文书
学校领导班子四风对照检查材料
2014/09/27 职场文书
社区服务理念口号
2015/12/25 职场文书
Python序列化与反序列化相关知识总结
2021/06/08 Python