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()


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


import Tkinter as tk

root = tk.Tk()

listbox = tk.Listbox(root)

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



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.