O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Expanding our demo

Open back up the demo file we created earlier, which shows off the current cursor location. Underneath your update_index function, we will add four more bindings which will be used to practice the utilization of these special strings:

def down_three_lines(event=None):    current_cursor_index = str(text.index(tk.INSERT))    new_position = current_cursor_index + "+3l"    text.mark_set(tk.INSERT, new_position)    return "break"def back_four_chars(event=None):    current_cursor_index = str(text.index(tk.INSERT))    new_position = current_cursor_index + "-4c"    text.mark_set(tk.INSERT, new_position)    return "break"

These two functions demonstrate the use of the +nl and -nc strings.

We get the cursor's current position in the same way as before, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required