This article describes a workaround for invalid Textctrl carriage return events in Wxpython. Share to everyone for your reference, as follows:
Today, using Wxptyhon's Textctrl control to develop the client encountered a problem, according to the logic of the HTML form, we should submit the query in Textctrl, but Wxpython Textctrl is very strange, Get in the car. Jump to the next control like tab action. In this case, to complete the query, either the mouse click the button, or you need to press two or more than two times.
Google, no answer, but got some useful information:
Types of events supported by Textctrl:
Evt_text: The text is changed by the user's input or by using SetValue () in the program to generate the event.
evt_text_enter: This event occurs when the user presses the ENTER key in a wx.te_process_enter-style text control.
Evt_text_url: If the Wx.te_rich or WX.TE_RICH2 style is set on a Windows system, and the Wx.te_auto_url style is set, The event is triggered when a mouse event occurs on a URL within a text control.
Evt_text_maxlen: If the maximum length of the control is specified with Setmaxlength (), the event is triggered when the user tries to enter a longer string.
For example, a warning message is displayed to the user.
Add Wxptyon Demos example, finally realized the solution:
1. When declaring an instance, you need to add a style property, such as:
Wx. Textctrl (Self,style=wx.te_process_enter)
2. Enter event for binding Textctrl
At first I used a button-like binding, and the results didn't work.
Copy the Code code as follows:
Self.element_panel.searchInput.Bind (WX. Evt_text_enter, Self.onsearch)
The correct way to declare it should be:
Copy the Code code as follows:
Self. Bind (WX. Evt_text_enter, Self.onsearch, Self.element_panel.searchInput)
Then declare the corresponding method in frame or panel to handle it.
More interested in Python related content readers can view this site topic: "Python data structure and algorithm tutorial", "Python Socket Programming Skills Summary", "Python function Tips Summary", "Python string manipulation Skills summary", " Python Introductory and Advanced Classic tutorials and Python file and directory Operations Tips Summary
I hope this article is helpful for Python program design.