【发布时间】:2019-12-17 09:43:54
【问题描述】:
我有一个从 csv 读取并使用 tkinter 显示的 4 列的表。我想在名为“已服务”的列中每一行的末尾添加一个复选按钮。然而,我没有得到一个检查按钮,而是得到'.!framed.!checkbut'。
这是我的代码:
from tkinter import *
from tkinter import ttk
from ttkthemes import ThemedStyle
import tkinter.font as font
import csv
root = Tk()
root.title("A") #title shown in bar
root.iconbitmap(r'C:/Users/...') #icon shown in bar
TableMargin = ttk.Frame(root)
TableMargin.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.state('zoomed') #fullscreen
# Setting Theme
style = ThemedStyle(TableMargin)
style.set_theme("black")
#Heading
label = ttk.Label(TableMargin, text='Orders')
label['font'] = font.Font(size=20, weight="bold")
label.grid(row=0, sticky=(N),pady=5)
#Designing of Table
style = ttk.Style()
style.configure("Treeview.Heading", font=(None, 13))
# scrollbarx = Scrollbar(TableMargin, orient=HORIZONTAL)
# scrollbary = Scrollbar(TableMargin, orient=VERTICAL)
tree = ttk.Treeview(TableMargin, columns=("Table No.", "Order", "Time", "Served"), height=400, selectmode="extended") #, yscrollcommand=scrollbary.set, xscrollcommand=scrollbarx.set
# scrollbary.config(command=tree.yview)
# scrollbary.pack(side=RIGHT, fill=Y)
# scrollbarx.config(command=tree.xview)
# scrollbarx.pack(side=BOTTOM, fill=X)
tree.heading('Table No.', text="Table No.", anchor=W)
tree.heading('Order', text="Order", anchor=W)
tree.heading('Time', text="Time", anchor=W)
tree.heading('Served', text="Served", anchor=W)
tree.column('#0', stretch=NO, minwidth=0, width=0)
tree.column('#1', stretch=NO, minwidth=0, width=100)
tree.column('#2', stretch=NO, minwidth=0, width=600)
tree.column('#3', stretch=NO, minwidth=0, width=100)
tree.column('#4', stretch=NO, minwidth=0, width=100)
tree.grid(row=0, pady=50,padx=190,sticky=(N, E, S))
with open('C:/Users/...', encoding = "utf-8-sig") as f:
reader = csv.DictReader(f, delimiter=',')
for row in reader:
table = row['Table']
order = row['Order']
time = row['Time']
var = IntVar()
served = ttk.Checkbutton(TableMargin, text="", variable=var)
served.grid()
tree.insert("", 1, values=(table, order, time, served))
【问题讨论】:
-
这能回答你的问题吗:how-can-i-add-checkbox-in-ttk-treeview
标签: python python-3.x tkinter