Is there a way to preselect/highlight a listbox item with the Tkinter GUI toolkit at the startup of the program without clicking the mouse on it?

Recommended Answers

All 4 Replies

Listbox.activate(n) selects line number n graphically and also adds it to Listbox.curselection()

Jeff

Sorry Jeff, this does not seem to highlight or select the line.

Hi!

import Tkinter as tk

root = tk.Tk()

listbox = tk.Listbox(root)
listbox.pack()

for item in ["one", "two", "three", "four"]:
    listbox.insert(tk.END, item)

listbox.selection_set(first=2)

root.mainloop()

Regards, mawe

Yeah, that works like a charm. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.