我想列出多个选中的项目使用复选框树视图并删除未选中的项目,

问题描述 投票:0回答:0
import tkinter as tk
from tkinter import *
from tkinter import ttk
from ttkwidgets import CheckboxTreeview
import os
import pandas as pd

desktop = os.path.expanduser(r"~\Desktop\BookingSYS") 
Database =desktop+r"\Database\Booking_2.xlsx"
filepath = Database
df = pd.read_excel(filepath)
window = tk.Tk()
window.title("Booking")
frame = tk.Frame(window)
frame.pack(fill="both", expand=True)
window.geometry('600x300')
tree = CheckboxTreeview(frame, column=('Model','Number','Status','Booking'), show=('headings','tree'), height=13)
tree.pack()
df_rows = df.to_numpy().tolist()
for row in df_rows:
    tree.insert("", 'end', values=row)
tree.column('#0', anchor=CENTER,stretch=NO, width=50)
tree.heading("# 0", text="Select")
tree.column("# 1", anchor=CENTER, stretch=NO, width=100)
tree.heading("# 1", text="Model")
tree.column("# 2",anchor=CENTER, stretch=NO, width=100)
tree.heading("# 2", text="Number")
tree.column("# 3", anchor=CENTER, stretch=NO, width=100)
tree.heading("# 3", text="Status")
tree.column("# 4", anchor=CENTER, stretch=NO, width=100)
tree.heading("# 4", text="Booking")
tree.bind('<ButtonRelease-1>', selectItem)
def selectItem(a):
    curItem = tree.focus()
    item_details = tree.item(curItem)
    ttk.Label(window, text=item_details.get("values")[1]).pack()
    print(item_details.get("values")[1])

window.mainloop()

我无法在列表中获取多个项目并创建条件。

这是我的结果。

我想把选中的值取到变量里运行,把数据传到excel中

enter image description here

我想在下面的链接中运行相同的内容。

https://www.lidorsystems.com/help/integralui/web-components/treeview/multi-select/

python-3.x excel tkinter treeview checkboxlist
© www.soinside.com 2019 - 2024. All rights reserved.