import tkinter as tk from tkinter import messagebox import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure p = 0.0 i = 0.0 class T2000ErdemGUI: def __init__(self, root): self.root = root self.root.title("T2000 Erdem") self.root.geometry("1024x600") # P- und I-Anteil Input Felder tk.Label(self.root, text="P-Anteil:").place(x=10, y=10) self.p_value = tk.DoubleVar() tk.Entry(self.root, textvariable=self.p_value).place(x=100, y=10) tk.Label(self.root, text="I-Anteil:").place(x=10, y=50) self.i_value = tk.DoubleVar() tk.Entry(self.root, textvariable=self.i_value).place(x=100, y=50) # Eingabefelder für Koordinaten tk.Label(self.root, text="Koordinaten der Drehmoment-Drehwinkel-Kennlinie:").place(x=10, y=90) self.coordinates_text = tk.Text(self.root, height=5, width=20) self.coordinates_text.place(x=20, y=110) self.coordinates_text.insert('end', '0,0\n5,15\n10,10\n90,10') # Eingabefeld für direkte Drehmomentvorgabe tk.Label(self.root, text="Soll-Drehmoment in Nm:").place(x=10, y=220) self.torque_value = tk.DoubleVar() tk.Entry(self.root, textvariable=self.torque_value).place(x=200, y=220) # Anzeige für aktuellen Drehwinkel und Drehmoment tk.Label(self.root, text="Aktueller Drehwinkel:").place(x=10, y=260) self.current_angle = tk.Label(self.root, text="0" + "°") self.current_angle.place(x=200, y=260) tk.Label(self.root, text="Aktuelles Drehmoment:").place(x=10, y=300) self.current_torque = tk.Label(self.root, text="0" + " Nm") self.current_torque.place(x=200, y=300) # Button zum Schließen der Anwendung self.close_button = tk.Button(self.root, text="Beenden", command=self.close_application) self.close_button.place(x=300, y=560) # Button zur Erstellung des Diagramms self.plot_button = tk.Button(self.root, text="Eingaben übernehmen", command=self.on_plot_button_click) self.plot_button.place(x=10, y=560) # Diagramm self.figure = Figure(figsize=(6,6), dpi=100) self.plot = self.figure.add_subplot(111) self.plot.set_xlim(0, 90) self.plot.set_ylim(ymin=0) self.plot.set_xlabel('Drehwinkel in Grad') self.plot.set_ylabel('Drehmoment in Nm') self.canvas = FigureCanvasTkAgg(self.figure, self.root) self.canvas.get_tk_widget().place(x=424, y=0) self.create_diagram() def close_application(self): if messagebox.askokcancel("Beenden", "Möchten Sie die Anwendung wirklich beenden?"): self.root.quit() def create_diagram(self): self.plot.clear() self.plot.set_xlim(0, 90) self.plot.set_xlabel('Drehwinkel in Grad') self.plot.set_ylabel('Drehmoment in Nm') coordinates = self.coordinates_text.get("1.0", tk.END).strip().split("\n") x_coords, y_coords = [], [] for coord in coordinates: x, y = map(float, coord.split(',')) x_coords.append(x) y_coords.append(y) self.plot.plot(x_coords, y_coords, marker='o', linestyle='-') self.plot.set_ylim(bottom=0) self.canvas.draw() def update_current_values(self, angle, torque): self.current_angle.config(text=str(angle)) self.current_torque.config(text=str(torque)) def save_set_values(self): p = self.p_value.get() i = self.i_value.get() def on_plot_button_click(self): self.create_diagram() self.save_set_values() # Anwendung starten root = tk.Tk() app = T2000ErdemGUI(root) root.mainloop()