wxPython event question

Tom Babbitt tbabbitt at commspeed.net
Thu Sep 20 03:20:46 CEST 2001


"Randy" <rangerrandy at hotmail.com> wrote in message
news:c6086c96.0109172048.296eb8ce at posting.google.com...
> Hi,
>
> I'm just learning wxPython, and I have a question about using the
> wxComboBox widget. After the user enters text into the widget, I want
> to capture the event from "Enter" key to process the new text.
>
> Thanks for any help,
>
> Randy

You can cach all the key up events,

from   wxPython.wx import *

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title, pos=wxDefaultPosition,
                 size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE):
        wxFrame.__init__(self, parent, ID, title, pos, size, style)
        panel = wxPanel(self, -1)
        sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                      'six', 'seven', 'eight']
        wxStaticText(panel, -1, "This example uses the wxComboBox control.",
                               wxPoint(8, 10))
        wxStaticText(panel, -1, "Select one:", wxPoint(15, 50), wxSize(75,
18))
        testcombo = wxComboBox(panel, 500, "default value", wxPoint(80, 50),
                   wxSize(95, -1), sampleList, wxCB_DROPDOWN)
        EVT_COMBOBOX(testcombo, 500, self.EvtComboBox)
        EVT_TEXT(testcombo, 500, self.EvtText)
        EVT_KEY_UP(testcombo,  self.EvtTextEnter)

    def EvtComboBox(self, event):
        print 'Pressed combo'

    def EvtText(self, event):
        print 'Pressed key'

    def EvtTextEnter(self, event):
        if wxKeyEvent.GetKeyCode(event) == 13:
            print 'Pressed Enter'



class App(wxApp):
    def OnInit(self):
        frame = MyFrame(None, -1, "test")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = App(0)
app.MainLoop()


If I cant find the event I want I look in the wxWindows help file and run
down the classes that the controll is derived from and experment with those
events.

Tom





More information about the Python-list mailing list