0

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?

3
Contributors
4
Replies
8
Views
11 Years
Discussion Span
Last Post by sneekula
0

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

Jeff

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.