基于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中exit、return、sys.exit()等使用实例和区别
May 28 Python
Python 基于Twisted框架的文件夹网络传输源码
Aug 28 Python
python使用for循环计算0-100的整数的和方法
Feb 01 Python
python实现杨氏矩阵查找
Mar 02 Python
Python 使用 attrs 和 cattrs 实现面向对象编程的实践
Jun 12 Python
浅析Django中关于session的使用
Dec 30 Python
Django接收照片储存文件的实例代码
Mar 07 Python
解决Python发送Http请求时,中文乱码的问题
Apr 30 Python
python3.6.8 + pycharm + PyQt5 环境搭建的图文教程
Jun 11 Python
python实现自动清理重复文件
Aug 24 Python
Django如何继承AbstractUser扩展字段
Nov 27 Python
Python创建SQL数据库流程逐步讲解
Sep 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
咖啡因含量是由谁决定的?低因咖啡怎么来?低因咖啡适合什么人喝
2021/03/06 新手入门
php实现的IMEI限制的短信验证码发送类
2015/05/05 PHP
PHP实现的链式队列结构示例
2017/09/15 PHP
PHP htmlspecialchars() 函数实例代码及用法大全
2018/09/18 PHP
php查看一个变量的占用内存的实例代码
2020/03/29 PHP
prototype 学习笔记整理
2009/07/17 Javascript
简短几句jquery代码的实现一个图片向上滚动切换
2011/09/02 Javascript
js调试工具Console命令详解
2014/10/21 Javascript
JavaScript实现向右伸出的多级网页菜单效果
2015/08/25 Javascript
JS之获取样式的简单实现方法(推荐)
2016/09/13 Javascript
ionic cordova一次上传多张图片(类似input file提交表单)的实现方法
2016/12/16 Javascript
DOM事件探秘篇
2017/02/15 Javascript
使用vue框架 Ajax获取数据列表并用BootStrap显示出来
2017/04/24 Javascript
vue2.0中goods选购栏滚动算法的实现代码
2017/05/17 Javascript
小发现之浅谈location.search与location.hash的问题
2017/06/23 Javascript
简单实现vue验证码60秒倒计时功能
2017/10/11 Javascript
详解webpack2异步加载套路
2018/09/14 Javascript
在vue中获取token,并将token写进header的方法
2018/09/26 Javascript
JavaScript Tab菜单实现过程解析
2020/05/13 Javascript
Vue项目打包编译优化方案
2020/09/16 Javascript
Python中的is和id用法分析
2015/01/26 Python
Python中用于转换字母为小写的lower()方法使用简介
2015/05/19 Python
对python中array.sum(axis=?)的用法介绍
2018/06/28 Python
Python字典推导式将cookie字符串转化为字典解析
2019/08/10 Python
解决python 执行shell命令无法获取返回值的问题
2020/12/05 Python
美国知名奢侈美容品牌零售商:Cos Bar
2017/04/21 全球购物
澳大利亚宠物商店:Petbarn
2017/11/18 全球购物
AURALog面试题软件测试方面
2013/10/22 面试题
九年级历史教学反思
2014/01/27 职场文书
家电业务员岗位职责
2014/03/10 职场文书
无房证明范本
2014/09/17 职场文书
作弊检讨书范文
2015/05/06 职场文书
2015年医务科工作总结范文
2015/05/26 职场文书
推广普通话的宣传语
2015/07/13 职场文书
python之np.argmax()及对axis=0或者1的理解
2021/06/02 Python
vue项目如何打包之项目打包优化(让打包的js文件变小)
2022/04/30 Vue.js