首页 > 代码库 > wxPython
wxPython
wxPython是python GUI的工具箱。
一, 安装
http://wiki.wxpython.org/How%20to%20install%20wxPython
稳定的wxpython 需要python 2.7版本,所以最好是用2.7
ptyhon2.7下载地址:
https://www.python.org/downloads/ 我装的是32 位的
然后下载wxpython 直接安装就OK了。
http://www.wxpython.org/download.php 你上面python安装多少位的 这里就下载多少位的
我是在win下使用的。
下面开始介绍如何使用wxpython
#!/usr/bin/env pythonimport wxapp = wx.App(False) # Create a new app, don‘t redirect stdout/stderr to a window.frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.frame.Show(True) # Show the frame.app.MainLoop()
Explanations:
app = wx.App(False) | Every wxPython app is an instance of wx.App. For most simple applications you can use wx.App as is. When you get to more complex applications you may need to extend the wx.App class. The "False" parameter means "don‘t redirect stdout and stderr to a window". |
wx.Frame(None,wx.ID_ANY,"Hello") | A wx.Frame is a top-level window. The syntax is x.Frame(Parent, Id, Title). Most of the constructors have this shape (a parent object, followed by an Id). In this example, we use None for "no parent" and wx.ID_ANY to have wxWidgets pick an id for us. |
frame.Show(True) | We make a frame visible by "showing" it. |
app.MainLoop() | Finally, we start the application‘s MainLoop whose role is to handle the events. |
by freemao
FAFU
free_mao@qq.com
wxPython