基于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 相关文章推荐
py2exe 编译ico图标的代码
Mar 08 Python
python刷投票的脚本实现代码
Nov 08 Python
Python内置数据结构与操作符的练习题集锦
Jul 01 Python
Python数据处理numpy.median的实例讲解
Apr 02 Python
在Python中使用gRPC的方法示例
Aug 08 Python
Python爬虫常用小技巧之设置代理IP
Sep 13 Python
python使用wxpy轻松实现微信防撤回的方法
Feb 21 Python
详解Python odoo中嵌入html简单的分页功能
May 29 Python
python实现点击按钮修改数据的方法
Jul 17 Python
Python爬虫程序架构和运行流程原理解析
Mar 09 Python
基于python计算滚动方差(标准差)talib和pd.rolling函数差异详解
Jun 08 Python
Python将字典转换为XML的方法
Aug 01 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系统流量分析的程序
2006/10/09 PHP
php 清除网页病毒的方法
2008/12/05 PHP
ThinkPHP与PHPExcel冲突解决方法
2011/08/08 PHP
关于mysql字符集设置了character_set_client=binary 在gbk情况下会出现表描述是乱码的情况
2013/01/06 PHP
php使用Jpgraph绘制3D饼状图的方法
2015/06/10 PHP
学习php设计模式 php实现观察者模式(Observer)
2015/12/09 PHP
详解Yii2高级版引入bootstrap.js的一个办法
2017/03/21 PHP
php表单文件iframe异步上传实例讲解
2017/07/26 PHP
详解no input file specified 三种解决方法
2019/11/29 PHP
js confirm()方法的使用方法实例
2013/07/13 Javascript
运行Node.js的IIS扩展iisnode安装配置笔记
2015/03/02 Javascript
JavaScript中exec函数用法实例分析
2015/06/08 Javascript
理解javascript函数式编程中的闭包(closure)
2016/03/08 Javascript
js实现select选择框效果及美化
2016/08/19 Javascript
利用jQuery插件imgAreaSelect实现获得选择域的图像信息
2016/12/02 Javascript
PHP+jquery+ajax实现分页
2016/12/09 Javascript
javascript实现圣旨卷轴展开效果(代码分享)
2017/03/23 Javascript
javascript中layim之查找好友查找群组
2021/02/06 Javascript
Python单体模式的几种常见实现方法详解
2017/07/28 Python
利用 python 对目录下的文件进行过滤删除
2017/12/27 Python
Python基于pandas实现json格式转换成dataframe的方法
2018/06/22 Python
python 把列表转化为字符串的方法
2018/10/23 Python
利用Python将文本中的中英文分离方法
2018/10/31 Python
python滑块验证码的破解实现
2019/11/10 Python
Python socket处理client连接过程解析
2020/03/18 Python
Django 删除upload_to文件的步骤
2020/03/30 Python
python使用自定义钉钉机器人的示例代码
2020/06/24 Python
html5 兼容IE6结构的实现代码
2012/05/14 HTML / CSS
英国自行车商店:AW Cycles
2021/02/24 全球购物
外语学院毕业生的自我鉴定
2013/11/28 职场文书
会计专业职业规划:规划自我赢取未来
2014/02/12 职场文书
计算机售后服务承诺书
2014/05/30 职场文书
植树造林的宣传标语
2014/06/23 职场文书
健康教育主题班会
2015/08/14 职场文书
导游词创作书写原则以及开场白技巧怎么学?
2019/09/25 职场文书
解决Python字典查找报Keyerror的问题
2021/05/26 Python