我正在尝试从文本框中删除单个字符,为此我显然需要知道要删除的字符的索引。我知道每个角色都拥有像Fazackerley一样的自己的索引,'F'将是1.0而'a'将是1.1但是当我得到第11个字母('y')时它将是1.10对吗?但这并不是因为它删除了'a',因为1.10与1.1相同,因为零是无限的,即使它们是无法看到的。因此,有人知道1.9之后的内容是非1.10或任何超过该数字的数字。
这是代码,如果有人想看它。
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()
这就是所有的代码,它可以正常工作,直到它达到'y'。
答案 0 :(得分:3)
使用字符串'1.10'
而不是浮动1.10
。
self.t1.delete('1.10') #deletes 'y' (line 1, column 10)
请参阅Text widget indices上的此参考资料。