我是python的新手,並試圖構建一個GUI,它從用戶的日期和日期中讀取數據,並相應地從csv文件中讀取數據並顯示尿液輸出(在csvimport函數中計算)。我也想在那段時間繪製特定時間和尿量的圖表。使用Tkinter的Python GUI和函數調用
任何人都可以幫助我嗎?我的代碼到目前爲止在下面,它不顯示任何GUI。請任何人都可以糾正基本錯誤,並幫助我運行這個?
import csv
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showwarning, showinfo
import datetime
#csv_file = csv.reader(open("C:\Users\Lala Rushan\Downloads\ARIF Drop Monitoring Final\ARIF Drop Monitoring Final\DataLog.csv"))
from Tools.scripts.treesync import raw_input
class App(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.in_file = None
button1 = Button(self, text="Browse for a file", command=self.askfilename)
button2 = Button(self, text="Count the file", command=self.takedate())
button3 = Button(self, text="Exit", command=master.destroy)
button1.grid()
button2.grid()
button3.grid()
self.grid()
def askfilename(self):
in_file = askopenfilename()
if not in_file.endswith(('.csv')):
showwarning('Are you trying to annoy me?', 'How about giving me a CSV file, genius?')
else:
self.in_file=in_file
def CsvImport(csv_file):
dist = 0
for row in csv_file:
_dist = row[0]
try:
_dist = float(_dist)
except ValueError:
_dist = 0
dist += _dist
print ("Urine Volume is: %.2f" % (_dist*0.05))
def takedate(self):
from_raw = raw_input('\nEnter FROM Date (e.g. 2013-11-29) :')
from_date = datetime.date(*map(int, from_raw.split('/')))
print ('From date: = ' + str(from_date))
to_raw = raw_input('\nEnter TO Date (e.g. 2013-11-30) :')
to_date = datetime.date(*map(int, to_raw.split('/')))
in_file = ("H:\DataLog.csv")
in_file= csv.reader(open(in_file,"r"))
for line in in_file:
_dist = line[0]
try:
file_date = datetime.date(*map(int, line[1].split(' ')[1].split('/')))
if from_date <= file_date <= to_date:
self.CsvImport(in_file)
except IndexError:
pass
root = Tk()
root.title("Urine Measurement")
root.geometry("500x500")
app = App(root)
root.mainloop()
感謝您的回答。我很困惑,我應該在哪裏使用** Entry **?在** takedate **功能?以及如何在GUI中使用** takedate **方法顯示該圖像? – rushan
@rushan增加了一些代碼。 – Lafexlos
你好。現在,當我在文本字段中輸入日期時,會發生以下錯誤:** TypeError:CsvImport()需要1個位置參數,但是有2個被給出**您能幫助我更多嗎? – rushan