我有一个从数据库检索信息,然后在Tkinter Treeview表中显示信息的功能。当程序使用sqlite3时,它运行良好。现在,我已切换到MySQL,现在没有。我根本没有更改树视图的格式。
我尝试过更改.tag_configure()方法的位置,并更改参数(背景色,标签名称)。没有任何办法可以使它再次工作。
from tkinter import *
from tkinter import ttk
class TreeviewTable(ttk.Treeview):
# Creates a gui_table with given columns.
def __init__(self, master, columns):
self.columns = columns
self.width = int(500 / (len(self.columns)))
ttk.Treeview.__init__(self, master, columns=self.columns,
show='headings', height=100)
for i in range(len(self.columns)):
self.column(self.columns[i], anchor='center', width=self.width)
self.heading('#{}'.format(str(i+1)), text=self.columns[i],)
self.pack(side=RIGHT, fill=BOTH, expand=1)
data = [
['Bottles', '1L', 500, '$1.62', '$810.00'],
['Bottles', 'Death Wish 1L', 300, '$2.76', '$828.00'],
['Labels', 'ALB 1L', 10500, '$0.11', '$1,155.00'],
['Capsules', 'ALB 1L', 3400, '$0.08', '$272.00'],
]
window = Tk()
window.geometry("%dx%d" % (500,130))
gui_table = TreeviewTable(window, columns=("Type", "Product", "Amount", "Price", "Total"))
gui_table.pack(side=RIGHT, fill=BOTH, expand=1)
for (index, row) in enumerate(data, 1): # Created striped rows
if (index % 2 == 0):
tag = 'even'
else:
tag = 'odd'
gui_table.insert("", END, values=row, tags=(tag,))
gui_table.tag_configure('even', background='#E8E8E8')
window.mainloop()