python使用使用tk画图并且可以实现数据筛选保存画图并且可以实现数据筛选保存
实现画图,数据筛选,保存
import shutil
from tkinter import *
import tkinter
from tkinter.filedialog import askdirectory
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from matplotlib.backend_bases import key_press_handler
import pandas as pd
import datetime
from get_file_list import get_one_type_file_list
import time
import stat
import os
class As:
"""
使用StringVar() 和 textvariable
对Button进行绑定
实现Button对数据进行操作
解决Button传参问题
StringVar()的数需要使用.get()获取值
"""
def __init__(self, master):
self.root = Frame(master)
self.num1 = StringVar() # 第一个数字
self.num2 = StringVar()
self.num3 = StringVar()
self.createpage()
def ii(self):
sys.exit(0)
# 绑定上面定义的键盘事件处理函数
def _quit(self):
"""点击退出按钮时调用这个函数"""
root.quit() # 结束主循环
root.destroy() # 销毁窗口
def selectPath(self):
path_ = askdirectory()
path.set(path_)
def createpage(self):
self.root.pack()
Label(self.root, text='起时间').grid(row=0, column=0, stick=W, pady=10)
# textvariable和StringVar的num1绑定
Entry(self.root, textvariable=self.num1).grid(row=0, column=1, stick=E)
Label(self.root, text='停时间').grid(row=0, column=10, stick=W, pady=10)
# textvariable和StringVar的num2绑定
Entry(self.root, textvariable=self.num2).grid(row=0, column=11, stick=E)
# Button传递参数
Label(self.root, text='文件名').grid(row=0, column=20, stick=W, pady=10)
# textvariable和StringVar的num1绑定
Entry(self.root, textvariable=self.num3).grid(row=0, column=21, stick=E)
Button(self.root, text='输入', command=self.btn_def).grid(row=1, column=10, stick=W)
Button(self.root, text='NEXT', command=self._quit).grid(row=1, column=20, stick=W)
Button(self.root, text='关闭', command=self.ii).grid(row=1, column=0, stick=W)
# Label(self.root, text="目标路径:").grid(row=0, column=0)
# Entry(self.root, textvariable=path).grid(row=0, column=1)
def btn_def(self):
# 使用.get()获取值
#num = int(self.num1.get()) + int(self.num2.get())
ts_st=self.num1.get()
ts_ed=self.num2.get()
mingzi=self.num3.get()
b=TS[0].strftime('%Y-%m-%d ')+ts_ed
a=(TS[0].strftime('%Y-%m-%d ')+ts_st)
starttime= int(time.mktime(datetime.datetime.strptime(a, '%Y-%m-%d %H:%M:%S').timetuple()))
endtime= int(time.mktime(datetime.datetime.strptime(b, '%Y-%m-%d %H:%M:%S').timetuple()))
#stt = datetime.datetime.strptime(mach['ts'], '%Y-%m-%d %H:%M:%S+0000')
for var,mach in enumerate(df1['ts_date']):
# c= int(time.mktime(mach.timetuple()))
if (mach - starttime) == 0:
cd=var
if (mach - endtime) == 0:
cq=var
del(df1['ts_date'])
df2=df1.loc[cd:cq] df2.to_csv(filePath+'\'+mingzi+'.csv',index=False)
评论0
最新资源