基于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装饰器decorator用法实例
Nov 10 Python
Python解决鸡兔同笼问题的方法
Dec 20 Python
一份python入门应该看的学习资料
Apr 11 Python
Python把csv数据写入list和字典类型的变量脚本方法
Jun 15 Python
Python lxml解析HTML并用xpath获取元素的方法
Jan 02 Python
关于Pycharm无法debug问题的总结
Jan 19 Python
Python模拟登录之滑块验证码的破解(实例代码)
Nov 18 Python
浅谈PyTorch的可重复性问题(如何使实验结果可复现)
Feb 20 Python
python之生成多层json结构的实现
Feb 27 Python
python DES加密与解密及hex输出和bs64格式输出的实现代码
Apr 13 Python
tensorflow使用freeze_graph.py将ckpt转为pb文件的方法
Apr 22 Python
python 中yaml文件用法大全
Jul 04 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代码优化的53个细节
2014/03/03 PHP
PHP fastcgi模式上传大文件(大约有300多K)报错
2014/09/28 PHP
php递归实现无限分类的方法
2015/07/28 PHP
javascript引导程序
2008/10/26 Javascript
网易JS面试题与Javascript词法作用域说明
2010/11/09 Javascript
jQuery前台数据获取实现代码
2011/03/16 Javascript
Javascript代码实现仿实例化类
2015/04/03 Javascript
JavaScript使用concat连接数组的方法
2015/04/06 Javascript
JS对HTML表格进行增删改操作
2016/08/22 Javascript
JavaScript 控制字体大小设置的方法
2016/11/23 Javascript
基于Bootstrap实现城市三级联动
2017/11/23 Javascript
css配合JavaScript实现tab标签切换效果
2018/10/11 Javascript
JavaScript命名空间模式实例详解
2019/06/20 Javascript
js实现图片实时时钟
2020/01/15 Javascript
Python中splitlines()方法的使用简介
2015/05/20 Python
pandas使用get_dummies进行one-hot编码的方法
2018/07/10 Python
python 重命名轴索引的方法
2018/11/10 Python
Python函数中参数是传递值还是引用详解
2019/07/02 Python
Python制作数据预测集成工具(值得收藏)
2020/08/21 Python
详解python命令提示符窗口下如何运行python脚本
2020/09/11 Python
通俗易懂了解Python装饰器原理
2020/09/17 Python
Python Tkinter实例——模拟掷骰子
2020/10/24 Python
python解决OpenCV在读取显示图片的时候闪退的问题
2021/02/23 Python
Kneipp克奈圃美国官网:德国百年精油配方的传承
2018/02/07 全球购物
乌克兰第一的珠宝网上商店:Gold.ua
2019/11/29 全球购物
The North Face意大利官网:服装、背包和鞋子
2020/06/17 全球购物
自我评价的范文
2014/02/02 职场文书
暑假社会实践心得体会
2014/09/02 职场文书
司法局群众路线教育实践活动开展情况总结
2014/10/25 职场文书
2014年后勤管理工作总结
2014/12/01 职场文书
2015年中秋节活动总结
2015/03/23 职场文书
公司回复函格式
2015/07/14 职场文书
三年级作文之趣事作文
2019/11/04 职场文书
《攀登者》:“海拔8000米以上,你不能指望任何人”
2019/11/25 职场文书
详细介绍Java中的CyclicBarrier
2022/04/13 Java/Android
Java 定时任务技术趋势简介
2022/05/04 Java/Android