K
kib2
Hi,
In a tkinter TextWidget I would like to retrieve the last typed word.
I've tried this with the 'wordstart' Expression [From the effbot site,
"wordstart" and "wordend" moves the index to the beginning (end) of the
current word. Words are sequences of letters, digits, and underline, or single
non-space characters.], but it fails :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Tkinter import *
root = Tk()
text = Text(root, font=("Calibri"))
text.pack()
# Insert some text inside (13 chars long)
text.insert(INSERT, "one two three")
# idx_st : the position of the cursor
# idx_ed : same but translated to the beginning of the last word ?
idx_st = text.index( "insert" ) # returns 1.13
idx_ed = text.index( "insert wordstart" ) # returns 1.13 too : why ?
print idx_st,idx_ed
print "Text=",text.get(idx_st,idx_ed)
mainloop()
Any idea ? Thanks in advance :
Kib².
In a tkinter TextWidget I would like to retrieve the last typed word.
I've tried this with the 'wordstart' Expression [From the effbot site,
"wordstart" and "wordend" moves the index to the beginning (end) of the
current word. Words are sequences of letters, digits, and underline, or single
non-space characters.], but it fails :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Tkinter import *
root = Tk()
text = Text(root, font=("Calibri"))
text.pack()
# Insert some text inside (13 chars long)
text.insert(INSERT, "one two three")
# idx_st : the position of the cursor
# idx_ed : same but translated to the beginning of the last word ?
idx_st = text.index( "insert" ) # returns 1.13
idx_ed = text.index( "insert wordstart" ) # returns 1.13 too : why ?
print idx_st,idx_ed
print "Text=",text.get(idx_st,idx_ed)
mainloop()
Any idea ? Thanks in advance :
Kib².