Ich erstelle eine GUI, um Live-Graphen von Temperatursensoren mit tkinter und Animationsfunktion von Matplotlib zu plotten. Ich bekomme schöne Live-Grafiken. Aber das Problem, mit dem ich konfrontiert bin, ist, dass die Live-Grafiken beginnen, sobald ich die Anwendung starte. Ich habe eine Schaltfläche zum Aufruf eines Befehls in Klasse StartPage erstellt, aber es funktioniert nicht. Ich möchte, dass meine Anwendung mit dem Sammeln von Daten und dem Zeichnen von Diagrammen beginnt, wenn ich auf klicke. Start Überwachung in der Klasse StartPagePython GUI und Animation
Es wäre ein großer Gefallen, wenn mir jemand dabei helfen könnte.
Thann Sie.
def animate(i):
ipcon = IPConnection() # Create IP connection
ptc1 = BrickletPTC(UID1, ipcon) # S3
ptc2 = BrickletPTC(UID2, ipcon) # S7
ptc3 = BrickletPTC(UID3, ipcon) # S7
ptc4 = BrickletPTC(UID4, ipcon) # S7
ipcon.connect(HOST, PORT) # Connect to brickd
temperature1 = ptc1.get_temperature() - 20
temperature2 = ptc2.get_temperature() + 6
temperature3 = ptc3.get_temperature() + 3
temperature4 = ptc4.get_temperature() + 29
l = [temperature1, temperature2]
avgTemp = np.mean(l)
avgTempM = str(avgTemp/100)
dataArrayavg = avgTempM.split(',')
tempavg = float(dataArrayavg[0])
tempCavg.append(tempavg)
avg.set_xlabel('Time [s]', fontsize = 10)
avg.set_ylabel('Temperature [°C]', fontsize = 10)
y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
avg.yaxis.set_major_formatter(y_formatter)
titleavg = "Average Room Temperature: " + str(temperature1/100) + " °C"
avg.set_title(titleavg, fontsize = 12)
avg.plot(tempCavg, "#483D8B")
f1.savefig('RoomTemperature.png')
f2.savefig('ObjectTemperature.png')
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
# Adding a logo to the startpage
logo = Image.open("Gemeinschaftslogo(5).jpg")
Image1 = ImageTk.PhotoImage(logo)
# defining the image label
imageLabel = Label(self, image = Image1)
imageLabel.image = Image1
imageLabel.pack(pady=30, padx=30)
#defining labels
label = ttk.Label(self, text="Zustandsüberwachung (Condition Monitoring) von industriellen Computertomographie-Systemen", font = LARGE_FONT,)
label.pack(pady=10, padx=10)
#creating button
#if agree then move to temperature graph
button1 = ttk.Button(self, text="Start Monitoring",
command=lambda: animate()) # with lambda we are moving from start page to page 1
button1.pack(pady=30, padx=30)
button2 = ttk.Button(self, text="Enter",
command=lambda: controller.show_frame(RoomTempGraph)) # with lambda we are moving from start page to page 1
ani1 = animation.FuncAnimation(f1,animate, interval = 1000)
app.mainloop()
Ihre Einrückung scheint gebrochen. Es ist nicht klar, wie viel Code in 'def animate (i) gehört:' –
@BryanOakley danke für die Antwort könnte ein Fehler beim Kopieren des Textes gewesen sein. Der Eindruck innerhalb von animiert (i) ist gut. – Ajay
Ich nehme an, das ist die Zeile, die die Animation auslöst: 'ani1 = animation.FuncAnimation (f1, animate, interval = 1000)'. Das sollte in den Button-Befehlen verschoben werden. Und im Befehl button1 scheint Ihr 'lambda: animate()' den 'i' Parameter zu verpassen. –