У меня есть текстовый виджет, который заполнен некоторым текстом. Я хотел бы добавить простую закладку (по Y) без , используя текстовые индексы (например, "50.2"). Как я могу это сделать?
Я пытался:
from tkinter import *
bookmarks = [] # create a list for bookmarks
def add_bookmark():
bookmark = textbox.yview() # get the vertical position of the view
bookmarks.append(bookmark) # and add it to the bookmarks' list
def goto_bookmark(bookmark):
textbox.yview_moveto(bookmark) # set the vertical positionn of the view
root = Tk() # create a root window
# set the column's and row's weight
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
textbox = Text(root) # create the Text widget
scrollbar = Scrollbar(root, command=textbox.yview) # create the Scrollbar widget, and attach it to the Text widget
textbox["yscrollcommand"] = scrollbar.set # attach the Text widget to the Scrollbar
# show the widgets using grid geometry manager
textbox.grid(row=0, column=0, sticky="nswe")
scrollbar.grid(row=0, column=1, sticky="nswe")
Button(root, text="Add bookmark", command=add_bookmark).grid() # create and show the "Add bookmark" button
Button(root, text="Goto lastbookmark", command=lambda: goto_bookmark(bookmarks[-1])).grid() # create and show the "Goto last bookmark" button
textbox.insert(END, "TEXT\n" *1000) # fill the textbox with something
root.mainloop() # start the mainloop
Но у меня есть это исключение, когда я пытаюсь перейти к закладке:
_tkinter.TclError: ожидаемое число с плавающей точкой, но получено "0,7501873126873126 0,7741633366633367"