基于wxpython实现的windows GUI程序实例
作者:皮蛋 时间:2022-07-03 21:33:01
本文实例讲述了基于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程序设计有所帮助。
标签:wxpython,windows,GUI
0
投稿
猜你喜欢
python爬取网页转换为PDF文件
2023-02-11 08:48:24
Vue中插槽slot的使用方法与应用场景详析
2023-07-02 17:04:11
vue基于websocket实现智能聊天及吸附动画效果
2024-04-30 08:45:20
Python数据分析之使用matplotlib绘制折线图、柱状图和柱线混合图
2023-09-16 23:18:09
如何使用Numpy创建三维矩阵
2022-10-28 05:07:54
python中文编码与json中文输出问题详解
2021-03-15 17:57:18
Python基础之类的定义和使用详解
2023-03-10 08:23:34
Python pygame绘制文字制作滚动文字过程解析
2022-06-10 13:21:11
Dreamweaver MX新功能试用:连续空格
2008-01-06 21:03:00
MySQL利用procedure analyse()函数优化表结构
2024-01-17 14:51:00
在线HTML编辑器原理(eweb原理)
2009-01-08 12:25:00
Python+Selenium实现短视频自动上传与发布的实践
2021-06-12 15:58:46
python二维列表一维列表的互相转换实例
2023-07-09 10:27:40
Python实现的查询mysql数据库并通过邮件发送信息功能
2024-01-21 11:51:36
详解Python3序列赋值、序列解包
2022-04-19 05:24:51
PHP多种序列化/反序列化的方法详解
2024-04-30 08:47:55
python调用文件时找不到相对路径的解决方案
2021-08-21 14:38:24
python使用wxpython开发简单记事本的方法
2022-05-15 18:06:12
CKeditor富文本编辑器使用技巧之添加自定义插件的方法
2024-04-18 09:52:24
Python PyInstaller库基本使用方法分析
2022-03-19 16:29:46