wxpythontextctrl

Is it possible to limit TextCtrl to accept numbers only in wxPython?


I want to have a text control that only accepts numbers. (Just integer values like 45 or 366)

What is the best way to do this?


Solution

  • IntCtrl, Masked Edit Control, and NumCtrl are all designed to do just this, with different levels of control. Checkout the wx demo under "More Windows/Controls" to see how they work.

    (Or, if you're instead really looking forward to doing this directly with a raw TextCtrl, I think you'd want to catch EVT_CHAR events, test the characters, and call evt.Skip() if it was an allowed character.)