基于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 相关文章推荐
tornado捕获和处理404错误的方法
Feb 26 Python
Python3基础之条件与循环控制实例解析
Aug 13 Python
Python命令行参数解析模块optparse使用实例
Apr 13 Python
Python基础教程之正则表达式基本语法以及re模块
Mar 25 Python
Python 制作糗事百科爬虫实例
Sep 22 Python
[原创]教女朋友学Python(一)运行环境搭建
Nov 29 Python
django多个APP的urls设置方法(views重复问题解决)
Jul 19 Python
简单了解Django ContentType内置组件
Jul 23 Python
ubuntu 安装pyqt5和卸载pyQt5的方法
Mar 24 Python
Jupyter Notebook远程登录及密码设置操作
Apr 10 Python
Django解决frame拒绝问题的方法
Dec 18 Python
pycharm远程连接服务器并配置python interpreter的方法
Dec 23 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 set_magic_quotes_runtime() 函数过时解决方法
2010/07/08 PHP
解决php使用异步调用获取数据时出现(错误c00ce56e导致此项操作无法完成)
2013/07/03 PHP
PHP实现简单搜歌的方法
2015/07/28 PHP
js jquery做的图片连续滚动代码
2008/01/06 Javascript
TextArea设置MaxLength属性最大输入值的js代码
2012/12/21 Javascript
CSS鼠标响应事件经过、移动、点击示例介绍
2013/09/04 Javascript
JQ获取动态加载的图片大小的正确方法分享
2013/11/08 Javascript
JS 日期比较大小的简单实例
2014/01/13 Javascript
JS实现部分HTML固定页面顶部随屏滚动效果
2015/12/24 Javascript
JavaScript 消息框效果【实现代码】
2016/04/27 Javascript
利用jquery禁止外层滚动条的滚动
2017/01/05 Javascript
javascript基础知识讲解
2017/01/11 Javascript
Vue.js -- 过滤器使用总结
2017/02/18 Javascript
js实现图片粘贴上传到服务器并展示的实例
2017/11/08 Javascript
详解redis在nodejs中的应用
2018/05/02 NodeJs
JS实现的判断方法、变量是否存在功能示例
2020/03/28 Javascript
详解基于vue的服务端渲染框架NUXT
2018/06/20 Javascript
微信小程序wx.getUserInfo授权获取用户信息(头像、昵称)的实现
2020/08/19 Javascript
JS sort排序详细使用方法示例解析
2020/09/27 Javascript
如何实现vue的tree组件
2020/12/03 Vue.js
[03:04]DOTA2英雄基础教程 影魔
2013/12/11 DOTA
Python使用pygame模块编写俄罗斯方块游戏的代码实例
2015/12/08 Python
python如何实现int函数的方法示例
2018/02/19 Python
Flask框架配置与调试操作示例
2018/07/23 Python
pycharm运行scrapy过程图解
2019/11/22 Python
python 画3维轨迹图并进行比较的实例
2019/12/06 Python
Python中logging日志的四个等级和使用
2020/11/17 Python
《那片绿绿的爬山虎》教学反思
2014/02/27 职场文书
成品库仓管员岗位职责
2014/04/06 职场文书
运输企业安全生产责任书
2014/07/28 职场文书
党员对十八届四中全会的期盼思想汇报范文
2014/10/17 职场文书
硕士论文致谢范文
2015/05/14 职场文书
Django rest framework如何自定义用户表
2021/06/09 Python
简单聊聊Vue中的计算属性和属性侦听
2021/10/05 Vue.js
SQL SERVER触发器详解
2022/02/24 SQL Server
Windows10安装Apache2.4的方法步骤
2022/06/25 Servers