Python_GUI程序设计
Python程序设计语言
Python GUI程序设计
张晓 西北工业大学计算机学院
zhangxiao@
2009-11-20
Python GUI编程概述
PyQT
wxPython
wxPython参考资料
活学活用wxPython
http:
Python程序设计语言 2
wxPython是什么
wxPython 实际是两件事物的组合体:
Python 脚本语言和 GUI 功能的
wxWindows 库
wxWindows库是为了最大可移植性的
C/C++ 库,而抽取 GUI 功能
Windows
X、KDE 或 Gnome 的 UNIX
wxPython 应用程序不仅快速和易于编写,而
且可以在不作任何更改情况下,运行在
Windows 或 UNIX 环境下
http:
Python程序设计语言 3
最小的 wxPython 程序
显示一个空白的窗口,标
题为First Windows
App对象
Frame对象
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "First Windows", size=(300, 300))
frame.Show(True)
app.MainLoop()
Python程序设计语言 4
显示JPG图片
使用image对象
将image对象传递
给frame
class Frame(wx.Frame): #2 wx.Frame子类
"""Frame class that displays an image."""
def __init__(self, image, parent=None, id=-1,
pos=wx.DefaultPosition,
title='Hello, wxPython!'): #3图像参数
"""Create a Frame instance and display image."""
#4 显示图像
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent, id, title, pos, size)
self.bmp = wx.StaticBitmap(parent=self, bitmap=temp)
Python程序设计语言 5
图形设计的基础
应用程序
窗口
控件
事件处理
Python程序设计语言 6
各对象的生命周期
应用程序
窗口 控件
事件处理
Python程序设计语言 7
增加一个控件
创建并修改状态栏
statusBar = self.CreateStatusBar() #1 创建状态栏
self.SetStatusText("This is the statusbar")
增加一个Menu
menuBar = wx.MenuB