基于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程序设计有所帮助。
0
投稿
猜你喜欢
- Python os.remove() 方法os.remove() 方法用于删除指定路径的文件。如果指定的路径是一个目录,将抛出OSError
- 方案5 使用xml参数 对sql server xml类型参数不熟悉的童鞋需要先了解下XQuery概念,这里简单提下XQuery 是用来从
- 语法df.drop_duplicates(subset = None,
- 实战场景 本篇博客学习字体反爬,涉及的站点是实习 x,目标站点地址直接百度搜索即可。可以看到右侧源码中出现了很多&ldqu
- 第一次写这类文章,有点儿紧张有点儿新奇有点儿痛苦,来CDC实习2个月啦,每天除了工作就是体验体验再体验,因为之前做了一些有关规范的工作,突然
- parent.html 中的代码为:<iframe marginwidth="0"
- 前言回调函数是我们在python编程中经常会遇到的一个问题,而想在将来某一时刻进行函数回调,可以使用call_later()函数来实现,第一
- 本文实例为大家分享了opencv实现双边滤波的具体代码,供大家参考,具体内容如下1、2D卷积#!/usr/bin/env python3#
- 前言:在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量
- 增大 SGA 已经缓冲看来对于性能的提升并不显著,加载时间只提升了 1.73%。下面我们增加 SGA 重做日志的大小: DB3: Log B
- 学习目的: 掌握文本框的用法 初次接触try…catch…语法 今天内容很轻松,用一个例子,输入年月日,判断输入是否正确 图片如下: 用个
- 概述迁移学习 (Transfer Learning) 是把已学训练好的模型参数用作新训练模型的起始参数. 迁移学习是深度学习中非常重要和常用
- 相信大家都试过将Python文件进行打包,来发给其他没有安装Python环境的用户使用,但通常情况下,打包生成的exe文件都很大,而产生这种
- 前言去年暑假参加了一个比赛,比赛内容中需要确定目标的位置 本来想全用图像完成的,最后发现不是很符合要求。比完赛之后,就忙别的事了。直到现在突
- 本文实例讲述了python对url格式解析的方法。分享给大家供大家参考。具体分析如下:python针对url格式的解析,可根据指定的完整UR
- 阅读上一篇:FrontPage XP设计教程5——表单的设计 在制作出图文并茂的网页之后,很多读者朋友还想让自己的网页能够播放音乐、视频等多
- 目录一.权限简介二.权限表结构设计:第一版三.权限表结构设计:第二版四.客户管理之动态“一级”菜单五.客户管理之动态“二级”菜单六.客户管理
- DataList Web 服务器控件 通过使用模板显示数据源中的项。通过操作组成 DataList
- 关联规则挖掘(Association rule mining)是数据挖掘中最活跃的研究方法之一,可以用来发现事情之间的联系,最早是为了发现超
- 之前我写过一篇文章介绍如何实现中国站长站的文章干扰码功能:《谈中国站长站的文章干扰码实现方法》 首发在asp之家。如果大家有兴趣可以先看看。