基于wxpython实现的windows GUI程序实例
作者:皮蛋 发布时间:2022-07-03 21:33:01
标签:wxpython,windows,GUI
本文实例讲述了基于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程序设计有所帮助。


猜你喜欢
- mysql 8.0.28版本安装配置方法图文教程,供大家参考,具体内容如下从 Mysql 官网下载 mysql 或直接点击这里下载下载完成后
- 概述从今天开始我们将开启一段自然语言处理 (NLP) 的旅程. 自然语言处理可以让来处理, 理解, 以及运用人类的语言, 实现机器语言和人类
- 正则表达式正则表达用来匹配字符串正则表达式匹配过程依次拿出表达式和文本中的字符串进行比价如果每个字符都能匹配,则匹配成功;一旦有匹配不成功的
- 前言最近空闲的时候看到了之前就关注的一个小站http://teahour.fm/,一直想把这里的音频都听一遍,可转眼间怎么着也有两年了,却什
- 由于python多线程无法发挥多核的作用,因此当计算量很大的时候就需要考虑多进程。只不过多进程比较麻烦一些,进程中通信向来是一件麻烦事。py
- 介绍本文将介绍基于OpenCV实现视频的循环播放。有以下三个步骤:首先设置一个frame的设置参数frame_counter,值为0在读帧时
- 示例matplotlib中的animation提供了动态绘图功能,下面列举一个最简单的动态绘制三角函数的例子,来初步演示一下。import
- 使用环境:Win10 x64 Python:3.6.4 SqlServer:2008R2 因为
- Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件Postman背景介绍用户在开发或者调试网络程序或者是网页B/
- Microsoft SQL Server 2005 Mobile Edition 3.0 (SQL Server Mobile) 支持两种与
- 我们的项目使用了bootstrapValidator来作为前端校验,但是表单里面有一个UEditor,它用bootstrapValidato
- 本文为大家分享了Ubuntu下Anaconda和Pycharm的配置方法,供大家参考,具体内容如下1.对于Ubuntu18.04,一开始会有
- 本文实例为大家分享了python OpenCV来表示USB摄像头画面的具体代码,供大家参考,具体内容如下确认Python版本$ python
- 之前版本的代理中,可以使用fiddler进行HTTP包的代理,但是代理HTTPS包时,执行错误 self._sslobj.do_
- 通过启用php.ini配置文件中的相关选项,就可以将大部分想利用SQL注入漏洞的骇客拒绝于门外。 开启magic_quote_gpc=on之
- 1.前言在移动商业广告的测试的工作中,经常会需要对广告请求进行捕获和分析,常使用的有两个测试工具:fiddler,Charles,这两个工具
- 一.怎样删除一个表中某个字段重复的列呀,举个例子 表[table1] id name 1 &nb
- 废话少说,上干活。for的基本操作for是用来循环的,是从某个对象那里依次将元素读取出来。看下面的例子,将已经学习过的数据对象用for循环一
- 应用场景在嵌入式开发中,常常需要将一个binary文件分割成多个文件,或者将一个binary的某块区域抓成一个单独文件。本篇blog以pyt
- 爬虫利器BeautifulSoup中find和find_all的使用方法二话不说,先上段HTML例子<html> &