如何用python获取企业微信打卡数据后实时将数据呈现在treeview中


def tt():
...
...
...
if punch_card:
# 插入数据语句
for i in coordinates:
#print(i)
#print((timestamp_datetime(i[1]).replace("/", "-"))[:-9])
if i[2] == '3F' and i[3] == '' \
and ((timestamp_datetime(i[1]).replace("/", "-"))[:-9])==today.strftime('%Y-%m-%d'):
sqly = "select t3.emp_name ,t3.card_no,t3.emp_no " \
"from 3l_eatuser t2,employees t3 " \
"where ifnull(t2.notes,0)=0 " \
"and t2.emp_id=t3.emp_no " \
"and ifnull(t3.card_no,'')<>'' " \
"and t2.userid='%s' " \
"group by t3.card_no,t3.emp_no,t3.emp_name " \
"union all " \
"select t2.username,'' card_no,'' emp_no " \
"from 3l_eatuser t2 " \
"where t2.notes=1 " \
"and t2.userid='%s' " \
"group by t2.userid,t2.username " \
"union all " \
"select t2.username,'' card_no,'' emp_no " \
"from 3l_eatuser t2 " \
"where t2.notes=2 " \
"and t2.userid='%s' " \
"group by t2.userid,t2.username " % (i[0], i[0], i[0])
cursor.execute(sqly)
resulty = cursor.fetchone()

tree.insert("", 0, values=(resulty['card_no'],resulty['emp_no'],resulty['emp_name'], timestamp_datetime(i[1]))) # 插入数win = tkinter.Tk()
# 设置窗口大小
winWidth = 800
winHeight = 600
# 获取屏幕分辨率
screenWidth = win.winfo_screenwidth()
screenHeight = win.winfo_screenheight()
x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)
win.title('3F就餐数据')
# 设置窗口初始位置在屏幕居中
win.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))

tree = ttk.Treeview(
master=win, # 父容器
height=100, # 表格显示的行数,height行
show='headings', # 隐藏首列
) # 表格
tree["columns"] = ("卡号", "工号", "姓名", "时间")
tree.column("卡号", width=200) # 表示列,不显示
tree.column("工号", width=200)
tree.column("姓名", width=200) # 表示列,不显示
tree.column("时间", width=200)
tree.heading("卡号", text="卡号") # 显示表头
tree.heading("工号", text="工号")
tree.heading("姓名", text="姓名") # 显示表头
tree.heading("时间", text="时间")
tree.pack()

tt()

win.mainloop()

获取打卡资料insert是OK的,但是没有实现实时更新数据进来,有新的打卡数据无法显示出来,只能显示执行时间前的数据;

所以想要一直执行tt(),但是没有反应,怎样才能获取实时数据显示呢,或者一直执行tt(),先清除tree在insert?
盼有大神指导一下,万分感谢~~~
while 1==1:
tt()
posted @ 2021-08-20 16:07  tiven_cc  阅读(595)  评论(0)    收藏  举报