Как собирать данные каждые десять секунд в один и тот же файл CSV с помощью tkinter - PullRequest
1 голос
/ 24 июня 2019

Я использую python для графического интерфейса и хочу измерять температуру в диапазоне 40 минут.Я хочу, чтобы программа сохраняла данные в формате csv в одном и том же файле csv каждые 10 секунд.По какой-то причине мой код сохраняет 10 CSV-файлов или 10 секунд, а не 1 CSV-файл с 10 точками данных.

#
def start(): # Stores Data Initial Columns
with open(txtName + time.strftime('%H:%M:%S', time.localtime()) + '.csv', 
'a') as data: 
        output = csv.writer(data)
        row = ['Time' , 'Left Hand Temp' , 'Right Hand Temp' , 'Fluid 
Temp Into Handle' , 'Fluid Temp Out of Handle' ]
        output.writerow(row)

def collect(): # Stores Data File Name With User Input    
with open(txtName + time.strftime('%H:%M:%S', time.localtime()) + '.csv', 
'a') as data:

##### THIS IS MY ATTEMPT AT A 10 second loop #######
 for everysecond in range(60):
     if everysecond % 10 is 0:
        output = csv.writer(data)
        rows = [time.strftime('%H:%M:%S', time.localtime()), 
sensor1.temperature, sensor2.temperature, 
sensor3.read_temp_c(),sensor4.read_temp_c()]
        output.writerow(rows)
#### I Think this is where the code for the 10 second loop should go, For 
some reason i cant get it to take data with respect to computer time. 

#Window
topFrame= Frame(root)
topFrame.pack()
bottomframe = Frame(root)
bottomframe.pack(side=BOTTOM)

#################### Buttons ##########################

button1 = Button(topFrame,text="Start Work-out", bg ='blue', command = 
start)
button2 = Button(topFrame,text="Collect", bg ='green', command = collect)
exitbutton = Button(root, bg = 'red', text='Stop Work-out', command = 
root.destroy)  

button1.pack(side = LEFT)
button2.pack()

Следует сохранять / обновлять данные в один и тот же CSV-файл каждые 10 секунд

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...