`
yexin218
  • 浏览: 959328 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

Getting Started with WxPython

阅读更多

第一个HelloWorld程序

#!/usr/bin/env python
import wx

app = 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()
 


接下来看看增加一些文件菜单:

'''
Created on Apr 24, 2010

@author: Leyond
'''
import wx
import os
class MyFrame(wx.Frame):
    """we simply dirive a new calss of wx"""
    def __init__(self,parent, title):
        wx.Frame.__init__(self,parent,title = title,size=(200,100))
        self.control = wx.TextCtrl(self,style = wx.wx.TE_MULTILINE)
        self.CreateStatusBar()
        
        filemenu = wx.Menu()
        menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open a file to edit")
        menuItem = filemenu.Append(wx.ID_ABORT,"&About","Information about this program")
        menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

        self.Bind(wx.EVT_MENU, self.OnAbout, menuItem)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
        self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)

        filemenu.AppendSeparator()
        menuBar =  wx.MenuBar()
        menuBar.Append(filemenu,"&File")
        self.SetMenuBar(menuBar)
        self.Show(True)
        
    def OnAbout(self,event):
        dlg = wx.MessageDialog(self,"A small text editon","About the editor")
        dlg.ShowModal()
        dlg.Destroy()
    def OnExit(self,e):
        self.Close()
        
    def OnOpen(self,e):
        """ Open a file"""
        self.dirname = ''
        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            f = open(os.path.join(self.dirname, self.filename), 'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()

        
app = wx.App(False)
frame = MyFrame(None,'Small editor')
app.MainLoop()

 

 

更多请参考:  http://wiki.wxpython.org/Getting%20Started

  • 大小: 11.6 KB
  • 大小: 39.1 KB
分享到:
评论

相关推荐

    wxpython中文教程wxpython中文教程

    wxpython中文教程wxpython中文教程wxpython中文教程wxpython中文教程wxpython中文教程wxpython中文教程wxpython中文教程wxpython中文教程wxpython中文教程

    wxPython几本好书

    几本很不错的关于python gui的wxPython的书,包括“wxPython in Action(中文版)” 活学活用wxPython “《wxPython in Action》Noel Rappin, Robin Dunn著 2006年版”

    wxPython-demo-4.0.4.tar.gz

    With wxPython software developers can create truly native user interfaces for their Python applications, that run with little or no modifications on Windows, Macs and Linux or other unix-like systems...

    wxPython in Action (2006).pdf

    The wxPython part of the story actually begins in 1995, with Harri Pasanen and Robin Dunn. Robin, who is one of the co-authors of the book, wrote the following about the history of wxPython, and we ...

    wxPython-docs-4.0.4.tar.gz

    With wxPython software developers can create truly native user interfaces for their Python applications, that run with little or no modifications on Windows, Macs and Linux or other unix-like systems...

    wxpython使用matplotlib的简单教程

    Scientific Visualization with wxPython and Matplotlib 使用的wxpython与matplotlib的科学可视化 Scott Pearse CSCI 5448 Spring 2011 上的讲义ppt的pdf版。简要表述了如何使用着两者,并同时使用以及效果图等内容...

    WxPython Application Development Cookbook(PACKT,2015)

    With a wide range of topics covered in the book, there are recipes to get the most basic of beginners started in GUI programming as well as tips to help experienced users get more out of their ...

    python2.4 and wxPython

    python2.4相对应的wxPython,还有很多库,一次性下载,不用费心去找了。

    wxPython开发参考书籍

    wxPython开发参考书籍

    wxpython grid.docx

    wxpython grid使用部分

    wxPython的wxAuiNotebook实现Tab页效果

    wxPython的wxAuiNotebook实现Tab页效果

    Part1 wxPython入门

    Part1 wxPython入门 , wxPython入门 , wxPython入门里面有实例讲解

    wxPython and PyOpengl源码

    wxPython and PyOpengl源码 演示如何在wxPython构建的GUI中使用pyopengl绘制场景

    wxpython for python2.4

    wxpython for python2.4 wxpython for python2.4 wxpython for python2.4 wxpython for python2.4 做python开发,注意自己的python版本是2.4

    wxPython-demo-4.0.6_wxpython官方demo_wxPython-demo_wxpython_DEMO_w

    wxpython 学习,各种demo集合,

    wxPython Application Development Cookbook

    wxPython Application Development Cookbook wxPython 开发入门

    wxpython for py2.6

    wxPython是Python编程语言的一个GUI工具箱。他使得Python程序员能够轻松的创建具有健壮、功能强大的图形用户界面的程序。它是Python语言对流行的wxWidgets跨平台GUI工具库的绑定。而wxWidgets是用C++语言写成的。 和...

    wxpython2.8.rar

    wxPython是一个用于创建桌面GUI应用程序的跨平台工具包。wxPython的主要作者是Robin Dunn。使用wxPython,开发人员可以在Windows,Mac和各种Unix系统上创建应用程序。

    python和wxpython资料合集

    wxPython_API.chm Python+中文手册.pdf Python入门指南 2.5b.pdf python教程.chm wxPIA_book wxPython_Tutorial wxpython-in-action-zh.pdf

    wxPython Grid Tips and Tricks

    wxPython Grid Tips and Tricks

Global site tag (gtag.js) - Google Analytics