wxPython笔记(Getting started with wxPython 1)

How to Learn wxPython: http://wiki.wxpython.org/How%20to%20Learn%20wxPython


Getting started with wxPython 1:http://wiki.wxpython.org/Getting%20Started

1. 两个ID符号:wxID_ANY, wxID_NONE   (http://docs.wxwidgets.org/2.8.12/wx_stdevtid.html)

wxWidgets defines a special identifier value wxID_ANY which is used in the following two situations:

  1) when creating a new window you may specify wxID_ANY to let wxWidgets assign an unused identifier to it automatically
  2) when installing an event handler using either the event table macros or wxEvtHandler::Connect, you may use it to indicate that you want to handle the events coming from any control, regardless of its identifier
Another standard special identifier value is wxID_NONE: this is a value which is not matched by any other id.

wxWidgets also defines a few standard command identifiers which may be used by the user code and also are sometimes used by wxWidgets itself. These reserved identifiers are all in the range between wxID_LOWEST and wxID_HIGHEST and, accordingly, the user code should avoid defining its own constants in this range.


2.wx.Window 是所有其他可视元素(button,menu等)的基类,wx.Frame是应用程序的顶层窗口。

A wx.Window is the base class from which all visual elements are derived (buttons, menus, etc) and what we normally think of as a program window is a wx.Frame. This is an unfortunate inconsistency that has led to much confusion for new users.


3. 获取wx支持的完整事件ID列表:

import wx

for x in dir(wx):
  if x.startswith('EVT_'):
      print x


4.通过Bind设置事件处理函数,wx.Event是各种事件(如wx.EVT_BUTTON)的基类。

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self,parent, title=title, size=(200,100))
        ...
        menuItem = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        self.Bind(wx.EVT_MENU, self.OnAbout, menuItem)


5.事件处理函数有统一的参数形式;通过event.Skip()可跳过事件的处理。

def OnAbout(self, e):
    if (some_condition):
        do_something()
    else:
        e.Skip()


6.模态对话框,注意对话框使用结束后使用了dlg.Destroy()销毁对话框。

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





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值