基于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找出文件中使用率最高的汉字实例详解
Jun 03 Python
python绘制铅球的运行轨迹代码分享
Nov 14 Python
python数据抓取分析的示例代码(python + mongodb)
Dec 25 Python
pandas创建新Dataframe并添加多行的实例
Apr 08 Python
用python处理MS Word的实例讲解
May 08 Python
Python+pandas计算数据相关系数的实例
Jul 03 Python
对python中的argv和argc使用详解
Dec 15 Python
解决Python对齐文本字符串问题
Aug 28 Python
Python处理session的方法整理
Aug 29 Python
django中url映射规则和服务端响应顺序的实现
Apr 02 Python
Django cookie和session的应用场景及如何使用
Apr 29 Python
python 中的@运算符使用
May 26 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中eclipse 用空格替换 tab键
2013/06/24 PHP
php设计模式之原型模式分析【星际争霸游戏案例】
2020/03/23 PHP
理解JavaScript中的事件
2006/09/23 Javascript
javascript showModalDialog 多层模态窗口实现页面提交及刷新的代码
2009/11/28 Javascript
vs2003 js文件编码问题的解决方法
2010/03/20 Javascript
jquery的$(document).ready()和onload的加载顺序
2010/05/26 Javascript
用js实现输入提示(自动完成)的实例代码
2013/06/14 Javascript
jQuery动态添加删除select项(实现代码)
2013/09/03 Javascript
常用的JS验证和函数汇总
2014/12/23 Javascript
jQuery链使用指南
2015/01/20 Javascript
简介JavaScript中的unshift()方法的使用
2015/06/09 Javascript
分享JS代码实现鼠标放在输入框上输入框和图片同时更换样式
2016/09/01 Javascript
解决Extjs下拉框不显示的问题
2017/06/21 Javascript
解决在vue项目中,发版之后,背景图片报错,路径不对的问题
2018/03/06 Javascript
vuejs实现标签选项卡动态更改css样式的方法
2018/05/31 Javascript
JavaScript闭包原理与用法实例分析
2018/08/10 Javascript
react build 后打包发布总结
2018/08/24 Javascript
微信小程序云开发(数据库)详解
2019/05/17 Javascript
解决vue 子组件修改父组件传来的props值报错问题
2019/11/09 Javascript
[54:54]Newbee vs Serenity 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/18 DOTA
Python3 入门教程 简单但比较不错
2009/11/29 Python
python发送邮件实例分享
2017/07/28 Python
Python模块文件结构代码详解
2018/02/03 Python
python3.7 使用pymssql往sqlserver插入数据的方法
2019/07/08 Python
python mqtt 客户端的实现代码实例
2019/09/25 Python
Python TCP通信客户端服务端代码实例
2019/11/21 Python
pytorch之Resize()函数具体使用详解
2020/02/27 Python
keras 如何保存最佳的训练模型
2020/05/25 Python
python中 _、__、__xx__()区别及使用场景
2020/06/30 Python
CSS3绘制有活力的链接下划线
2016/07/14 HTML / CSS
简述安装Slackware Linux系统的过程
2012/05/08 面试题
北京奥运会口号
2014/06/21 职场文书
安全生产年活动总结
2014/08/29 职场文书
2015年打非治违工作总结
2015/04/02 职场文书
保安辞职申请书应该怎么写?
2019/07/15 职场文书
Python中zipfile压缩包模块的使用
2021/05/14 Python