user2387537
user2387537

Reputation: 399

Tkinter Textbox index delete 1.10 not working

I'm trying to delete a single character from a Text box and to do that I obviously need to know the index of the character that I want to delete. I know that each character has it's own index like Fazackerley for instance, the 'F' would be 1.0 and the 'a' would be 1.1 but when I would get to the 11th letter ('y') it would be 1.10 right? But it's not because then it deletes the 'a' because 1.10 is the same as 1.1 as the zeros are infinite even though they can't be seen. So does anyone know what comes after 1.9 that isn't 1.10 or any number that is above that.

Here's the code if anyone wants to look at it.

from tkinter import *
import time
import random

class Application(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.widgets()

    def widgets(self):
        self.t1 = Text(width = 35, height = 5, wrap = WORD)
        self.t1.grid(row = 0, column = 0, sticky = W)
        self.count = 0
        self.coor = 1.0
        for x in range(1):
            self.t1.insert(END, 'fazackerley')
            self.count += 1
            time.sleep(0.5)
            root.update()
            self.t1.delete(1.10) #deletes 'a' (index 1.1) not 'y' 

root = Tk()
root.title()
root.geometry('250x250')
app = Application(root)
root.mainloop()

That's all of the code and it works fine until it gets upto 'y'.

Upvotes: 1

Views: 384

Answers (1)

unutbu
unutbu

Reputation: 880359

Use the string '1.10' rather than the float 1.10.

self.t1.delete('1.10') #deletes 'y' (line 1, column 10)

See this reference on Text widget indices.

Upvotes: 3

Related Questions