Dealing with the Tkinter Text Widgets Indexing System. Dealing with the Tkinter Text Widgets Indexing System. tkinter tkinter

Dealing with the Tkinter Text Widgets Indexing System.


Assuming that 'index' is a string since you are dealing with a text widget index:

int(index.split('.')[-1])

If you really do have a floating point number, you need to convert it to a string first:

int(str(index).split('.')[-1])


The Tkinter Text Widget

Note that line/column indexes may look like floating point values, but it’s seldom possible to treat them as such (consider position 1.25 vs. 1.3, for example). I sometimes use 1.0 instead of “1.0” to save a few keystrokes when referring to the first character in the buffer, but that’s about it.

You should have mentioned the context in the OP (Tkinter Text Widget). What you're doing has nothing to do with floating-point numbers at all. You're just finding a period, followed by an integer. You should never store this value in any floating-point variable. (Doing so could have dire consequences.)


def after_period(number):    return int(str(number).partition(".")[2])