我将包含代码,但只包含一小部分。
import tkinter as tk
from tkinter import messagebox
from struct import unpack
from codecs import decode
class Graphicaluserinterface(tk.Frame):
inputliste = []
def __init__(self,master=None):
super().__init__(master)
self.grid()
self.fileopenname = tk.StringVar()
self.filesavename =tk.StringVar()
self.entrystring = tk.IntVar()
self.taktzykluszeit = tk.DoubleVar()
self.taktunterschiedboolean = tk.BooleanVar()
self.menubar = tk.Menu(self)
self.create_widgets()
self.entrystring.set(9)
self.taktzykluszeit.set(0.0)
self.taktunterschiedboolean.set(False)
def create_widgets(self):
self.programmstart = tk.Button(self, text = "Start Program")
self.programmstart.grid(row=10,column=8,sticky = "W")
self.programmstart["command"]=lambda:[self.fileselectwarning(),self.writealldatafile(),self.writeselecteddata()]
def zugriffaufdatenverarb(self):
#this is the method that accesses the data processing methods
inputfilepath2 = self.fileopenname.get()
self.inputfilepath = inputfilepath2
a = Trennzeichenalgorithmus
a.fileopening123(self)
a.trennzeichenmethode(self)
b = Datenverarbeitung
b.uhrzeitdermessung(self)
b.drehzahl(self)
b.temperatursensoren(self)
b.analogvoltsensoren(self)
b.analogmilliampsensoren(self)
b.drehmomentsensoren(self)
def writealldatafile(self):
import csv
from itertools import zip_longest
outputfilepath2 = self.filesavename.get()
self.outputfilepath = outputfilepath2
allelisten = [self.datumstring,self.ganzesdatum,self.milliundmikroliste_3,self.drehzahlgsm1_4,self.drehmomentgsm1_4,
self.drehzahlgsm2_4,self.drehmomentgsm2_4]
column_titles = []
column_titles.append("Datum")
column_titles.append("")
column_titles.append("Taktzykluszeit in s")
column_titles.append("Drehzahl_GSM_1 in 1/min")
column_titles.append("Drehmoment_GSM_1 in Nm")
column_titles.append("Drehzahl_GSM_2 in 1/min")
column_titles.append("Drehmoment_GSM_2 in Nm")
for j in range(len(self.analogvolt_3)):
column_titles.append("Analogvoltsensor"+"_"+str(j+1)+" in +-10V")
allelisten.append(self.analogvolt_3[j])
for l in range(len(self.analogmilliamp_3)):
column_titles.append("Analogamperesensor"+"_"+str(l+1)+" in 20 mA")
allelisten.append(self.analogmilliamp_3[l])
for i in range(len(self.thermoelement_3)):
column_titles.append("Thermoelement"+"_"+str(i+1)+" in °C")
allelisten.append(self.thermoelement_3[i])
for k in range(len(self.pt100element_3)):
column_titles.append("Pt-100-Element"+"_"+str(k+1)+" in °C")
allelisten.append(self.pt100element_3[k])
column_titles_tuple = tuple(column_titles)
export_data1 = zip_longest(*allelisten, fillvalue = "")
with open(self.outputfilepath,"w+",encoding="ISO-8859-1") as csvwithalldata:
alldata=csv.writer(csvwithalldata,delimiter=";")
alldata.writerow(column_titles_tuple)
alldata.writerows(export_data1)
csvwithalldata.close()
root = tk.Tk()
app = Graphicaluserinterface(master=root)
app.master.title("Test")
app.master.minsize(800,300)
root.config(menu=app.menubar)
app.mainloop()
“ writealldatafile”方法将所有数据处理列表一起实现为一个列表,该列表被写入文件中。如果您需要更多代码或对我的代码进行详细说明,请告诉我。
答案 0 :(得分:0)
好吧,我想我找到了一个简单的解决方案。读取二进制文件时,将使用十六进制值创建一个列表。然后,此列表用于创建所有其他列表,这些列表有时会写入输出文件中。因此,在创建的第一个列表上使用del命令解决了我的问题。