0

I have a application which ask the user for a input (wx Python). I want to control what is inside the TextCtrl so I added the event: wx.EVT_CHAR. The function work properly except that I want the position of the curently entered charater.

Let say I only want a charater to be at one place, I need the position of it. That my prob.

    def handle_keypress(self, event, entry):
        key = event.GetKeyCode()
        keycode = [1,2,3,4,5,6] #example

        bool = False
        for char in keycode:
            if key == char:
                bool = True
                break

        if bool == True:
            event.Skip()

thx, I hope you guys can help me!

PS: Sorry for my bad english :(

EDIT: Problem solved!

I though the problem would be in the EVT_CHAR: http://www.wxpython.org/docs/api/wx.KeyEvent-class.html

But it's not, it was in the TextCtrl: http://www.wxpython.org/docs/api/wx.TextCtrl-class.html

The method GetInsertionPoint() worked!

user1586263
  • 61
  • 1
  • 3

1 Answers1

1
self.text_ctrl.GetInsertionPoint()

i think is what you want

in your example "CCC" would always return 0 but this should return the actual position of the carat

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179