I want to focus on multiple lines in tree.view on Tkinter.

Asked 2 years ago, Updated 2 years ago, 119 views

I want to focus on multiple lines in Tkinter's tree.view.

For example, I want to focus only "3" and "4" from the 10 lines of tree.view list, but for some reason only "4" is focused.

If you know how to select multiple lines, please let me know.
Thank you for your cooperation.

Run Screen

import tkinter ask
import tkinter.ttk as ttk

num_frame=tk.Tk()# Route Frame Creation
num_frame.title("")#Title Settings
num_frame.geometry("180x306")# Screen Size Settings
num_frame1=tk.LabelFrame(num_frame,font=(",12),bd=2,padx=5,pady=5,relief="ridge",labelanchor='nw',text="",width=150,weight=240,bg="#00599D")
num_frame1.pack(fill="both")
style=ttk.Style()
style.configure ("Treeview", font=(", 12)) # Change the font size in TreeView
style.configure("Treeview.Heading", font=(",14, "bold"))# Change the font size of the header and set bold text
tree=ttk.Treeview(num_frame1, height=100)
tree ["columns"] = (1)
tree ["show"] = "headings" # Table Style Settings
tree.column (1, width=100)
tree.pack()
num_lst=("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
i = 0# initialization
for line in num_lst:
    iid=tree.insert("", "end", tags=i, values=(line))
    # change the background color by determining whether the tag is odd or even
    if line=="3" or line=="4":
        tree.focus(iid)#Focus data (internal selection on the program)
        tree.selection_set(iid)#Select data (as selected by appearance)

python tkinter tk

2022-09-30 21:46

1 Answers

With this article in mind, if you want to select more than one, you can choose selection_add() or selection_toggle() instead of selection_set().

Tk Treeview Focus().How do I Get Multiple Selected Lines?

Usettk.treeview.selection().
It gives the selected items.See also other Treeview methods with selection prefix such as,
The selected item appears. See also other Treeview methods with the following selection prefixes:

selection_add
selection_remove
selection_toggle


2022-09-30 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.