python - 如何突出显示 csv 数据的行差异?
问题描述
我有这张桌子:
我使用以下代码创建了带有树视图的 tkinter 表:
from tkinter import *
import tkinter.ttk as ttk
import csv
root = Tk()
root.title("Python - Import CSV File To Tkinter Table")
width = 500
height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d+%d+%d" % (width, height, x, y))
root.resizable(0, 0)
TableMargin = Frame(root, width=500)
TableMargin.pack(side=TOP)
scrollbarx = Scrollbar(TableMargin, orient=HORIZONTAL)
scrollbary = Scrollbar(TableMargin, orient=VERTICAL)
tree = ttk.Treeview(TableMargin, columns=("Var1", "Var2", "Var3",'Var4'), 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('Var1', text="Var1", anchor=W)
tree.heading('Var2', text="Var2", anchor=W)
tree.heading('Var3', text="Var3", anchor=W)
tree.heading('Var4', text="Var4", anchor=W)
tree.column('#0', stretch=NO, minwidth=0, width=0)
tree.column('#1', stretch=NO, minwidth=0, width=120)
tree.column('#2', stretch=NO, minwidth=0, width=120)
tree.column('#3', stretch=NO, minwidth=0, width=120)
tree.column('#3', stretch=NO, minwidth=0, width=120)
tree.pack()
with open('./dati/esempio.csv') as f:
reader = csv.DictReader(f, delimiter=',')
for row in reader:
emp_id = row['Var1']
name = row['Var2']
dt = row['Var3']
ti = row['Var4']
tree.insert("", 5, values=(emp_id, name, dt,ti))
root.mainloop()
如何突出显示 python Tkinter 中的行数据差异,如上表所示?每一行与前一行。
解决方案
推荐阅读
- javascript - Webpack(VueJS) 为 FIrefox 和 Chrome 制作不同的图像路径
- java - 使用方法更改变量,然后无法将值分配给另一个变量
- javascript - Javascript - 有没有办法从函数调用参数中获取字符串?
- javascript - 静态函数不是函数javascript
- python - 仅当 25% 分位数高于给定值时才选择数据
- xpath - xpath - 如何从 Quora 中的节点获取文本?
- sitecore-sxa - Sitecore-SXA 搜索结果和方面
- post - 带参数的 Axios Vuejs POST 请求
- javascript - 在 JavaScript 对象中制作重复动画循环
- hdfs - Pig 无法创建 .bz2 文件但创建 .deflate 文件