I am looking for a way to set the current selection inside a Tkinter text widget.
I already tried to set it with mark_set()
, but it doesn't work...
text_widget.mark_set("sel.first", 1.0)
text_widget.mark_set("sel.last", END)
Would anyone know how to work this one out?
sel
is a tag, not a mark, so you need to use the tag commands, such as tag_add
import Tkinter as tk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.text = tk.Text(self)
self.text.pack()
self.text.insert("1.0", "Hello, world")
self.text.tag_add("sel", "1.7", "1.12")
self.text.focus_force()
app = SampleApp()
app.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With