【发布时间】:2009-06-22 10:52:04
【问题描述】:
我是第一次尝试 wxpython,所以我需要一个示例程序,详细说明如何运行它
【问题讨论】:
标签: wxpython
我是第一次尝试 wxpython,所以我需要一个示例程序,详细说明如何运行它
【问题讨论】:
标签: wxpython
有几个可用的教程。您可能想从这里开始:http://wiki.wxpython.org/Getting%20Started
除其他外,此页面还包括一些示例应用程序,从简单的“Hello World”到事件处理和其他示例。
【讨论】:
这里有几个对初学者有用的教程。这对我很有帮助。您可以从初级到中级学习。
【讨论】:
首先确保您的系统上安装了 python 2.7.x,然后前往wxpython download 页面并为您的系统下载相关的二进制文件以及文档和演示。如果您使用的是 linux,请从您的发行版中获取 wxpython存储库。 将以下脚本复制并保存为 app.py
#! /usr/bin/env python
import wx
#implimenting a the frame
class MyFrame(wx.Frame):
#Begining __init__()
def __init__(self):
wx.Frame.__init__(self, parent = None, id = -1, title = "A simple App", pos = (-1, -1), size = (400, 300), style = wx.DEFAULT_FRAME_STYLE)
#End __init__()
#implimenting the application
class MyApp(wx.App):
#Begining OnInit(self)
def OnInit(self):
self.frame = MyFrame()
self.frame.Show(True)
self.SetTopWindow(self.frame)
return True
#End OnInit(self)
#first chech whether the script is being run as the main script if so run the main application loop
if __name__ == '__main__':
app = MyApp()
app.MainLoop()
在 windows 上,只需双击脚本在 unix 系统上运行它首先启动终端并将工作目录更改为您保存脚本的目录,然后执行 chmod +x app.py 然后 ./app.py 运行它。
您还应该查看“wxpython in action 2012”一书。
【讨论】: