Wxpython program triggers menu or button events, wxpython triggers

Source: Internet
Author: User

Wxpython program triggers menu or button events, wxpython triggers

Recently, I have gradually become familiar with wxpython and compiled several small GUI programs. There is no need to trigger control events in code in the GUI. In other Gui languages, postevent and triggerevent call the function of the event name, which is very convenient.

How can we solve this problem in wxpython? The last simple code.

Class frame (wx. Frame): ID_Help = wx. NewId ()
Def _ init _ (self, frame ):
Super (TaskBarIcon, self). _ init __()
Self. frame = frame
Self. Bind (wx. EVT_MENU, self. OnHelp, id = self. ID_Help)
......
Self. Bind (wx. EVT_CHECKBOX, self. OnShowDetail, self. cbxShowDetail) self. Bind (wx. EVT_BUTTON, self. OnPrint, self. btnPrint )...... Def CreatePopupMenu (self): menu = wx. Menu () menu. Append (self. ID_Help, U' help & F1 ') return menu ......
Def ShowMain ():
# Trigger menu event, id = self. ID_Help
IRet = wx. PostEvent (self, wx. CommandEvent (wx. EVT_MENU.typeId, self. ID_Help ))
Return iRet

Def PrintMain ():
# Trigger button event, id = self. btnPrint. GetId ()
# It is equivalent to executing the OnPrint () event bound to btnPrint.
IRet = wx. PostEvent (self, wx. CommandEvent (wx. EVT_BUTTON.typeId, self. btnPrint. GetId ()))
Return iRet

Def PrintMain ():
# Trigger the checkbox event, id = self. cbxShowDetail. GetId ()
# The Event OnShowDetail () bound to cbxShowDetail is executed.
Self. cbxShowDetail. SetValue (True)
IRet = wx. PostEvent (self, wx. CommandEvent (wx. EVT_CHECKBOX.typeId, self. cbxShowDetail. GetId ()))
Return iRet

 


Explanation:

Wx. PostEvent (self, wx. CommandEvent (wx. EVT_CHECKBOX.typeId, self. cbxShowDetail. GetId ()))

Parameter 1. self indicates the window handle for processing postevent.

Parameter 2, event = wx. CommandEvent (eventtype, eventid)
Eventtype: wx. evt_menu, wx. evt_button, and wx. evt_checkboxx.

Eventid is the id of the control bound to the event.

 

Above.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.