python - 每隔一段时间用 tkinter 读取 Pandas
问题描述
我有一个文本文件,我通过 pandas 将其读取为 csv,我想在 tkinter 中显示我正在使用 Entry 的数据,我的 csv 文件包含大约 400 行,但我想在第一个屏幕上只显示前 40 行,然后按下下一步按钮接下来的第 41 到第 81 行应该出现在屏幕上,依此类推....
如何在 pandas 中一次迭代 40 行的行?还有其他在 tkinter 中显示文本文件的最佳方法吗?基本上我想要一个 DATE_TIME 上的下拉选项,以便每当用户选择 00 小时然后屏幕上只显示 00 小时数据,当用户选择 01 小时然后只有 01 小时数据显示在当前屏幕上。我想要在我的第二个 Windows TIA 上也有一个退出按钮。
Sample Data
Name: Longitude(degree) Latitude(degree) DATE_TIME Mean Sea Value (m) DRY or WET
SD 87.0308 21.4441 00:00 IST 05-08-2019 -0.0467 DRY
Sea1 87.0544 21.4152 00:00 IST 05-08-2019 -1.0653 DRY
4K 86.9927 21.4197 00:00 IST 05-08-2019 -0.1331 DRY
4KP1 86.9960 21.4166 00:00 IST 05-08-2019 -0.0863 DRY
Name: Longitude(degree) Latitude(degree) DATE_TIME Mean Sea Value (m) DRY or WET
SD 87.0308 21.4441 01:00 IST 05-08-2019 -0.0329 DRY
Sea1 87.0544 21.4152 01:00 IST 05-08-2019 -0.4067 DRY
4K 86.9927 21.4197 01:00 IST 05-08-2019 -0.0897 DRY
4KP1 86.9960 21.4166 01:00 IST 05-08-2019 -0.0676 DRY
编写的代码
from tkinter import *
import pandas as pd
root=Tk()
root.geometry('150x150')
root.wm_title("WALPS_PROJECT")
root.iconbitmap("images/icon.ico")
Frame1=Frame(root,bd=5)
Frame1.pack(side=BOTTOM)
# bottomframe=Frame(root)
# bottomframe.pack(side='bottom')
# df=pd.read_csv("p_1_data.txt",sep="\t")
# row,column=df.shape
def showdata():
top=Toplevel()
df = pd.read_csv("p_1_data.txt", sep="\t",header=None)
row, column = df.shape
top.title("---DATA WINDOWS---")
top.iconbitmap("images/icon.ico")
for r in range(40):
for c in range(column):
e1=Entry(top)
e1.insert(1,df.iloc[r,c])
e1.grid(row=r,column=c,padx=5,pady=5)
Exitbutton=Button(top,text="EXIT",fg="red",bd=5, width=10, height=10,command=root.quit)
Exitbutton.pack(in_=top, side=LEFT)
showbutton=Button(Frame1,text="Show Data",fg="red",bd=5, width=10, height=10,command=showdata)
showbutton.pack(in_=Frame1, side=LEFT)
#showbutton.place(relx=0.5,rely=0.5,anchor=CENTER)
Exitbutton=Button(Frame1,text="EXIT",fg="red",bd=5, width=10, height=10,command=root.quit)
Exitbutton.pack(in_=Frame1, side=LEFT)
root.mainloop()
解决方案
推荐阅读
- sql-server - 在 MSSQL 中减去两列
- python - Python(列表):如何对重复的标签进行分组,总结它们各自的值
- javascript - 将打印所有数字和到目前为止在 JS 中打印的数字总和的程序
- php - 使用 php 设置 .dll、.zip 和 .so 文件的元数据
- python - 如何在 Odoo 12 中使用 many2one 字段?
- node.js - 在 Firebase Cloud Functions 的 tmp 目录中创建文件夹
- javascript - hapijs - 如何在重定向到另一条路线时传递标头
- xml - 如何在 xslt 文件中使用外部 xml 架构?
- ios - 从 viewDidDisappear 但不是从按钮 Swift 4 调用函数时出现 Fond nil 错误
- flutter - 如何使用流畅的动画从页面视图中删除页面?