Python Programm mit PiCtory
Posted: 25 Jul 2025, 09:15
Hallo,
ich versuche aktuell ein Andon System zu erstellen, sprich wenn ich auf eine Taste drücke, soll sie Rot, Gelb oder Grün anzeigen. Mein Programm ist in Python geschrieben. Ich habe ein fertiges Bedienfeld und dieses mit meinem RevPi Connect 5 mit DIO Modul verbunden. Jetzt verstehe ich jedoch nicht genau, was ich in PiCtory machen muss, damit sich die Farbe in meinem Programm per Knopfdruck verändert. Ich bin leider relativ neu in der Materie und blicke noch nicht ganz durch.
Dies ist mein Programm als Code:
import tkinter as tk
class MachineFrame(tk.Frame):
def __init__(self, master, machine_id):
super().__init__(master, bd=2, relief="groove", padx=5, pady=5)
self.machine_id = machine_id
self.status = "OK"
# Titel
self.label = tk.Label(self, text=f"Maschine {machine_id}", font=("Arial", 12, "bold"))
self.label.pack(pady=5)
# Status-Anzeige
self.status_label = tk.Label(self, text=f"Status: {self.status}", bg="green", fg="white", width=40, height=3, font=("Arial", 10))
self.status_label.pack(pady=5)
# Button-Gruppe
button_frame = tk.Frame(self)
button_frame.pack()
tk.Button(button_frame, text="OK", bg="green", fg="white", width=8,
command=lambda: self.set_status("OK", "green")).grid(row=0, column=0, padx=2)
tk.Button(button_frame, text="Warnung", bg="yellow", fg="black", width=8,
command=lambda: self.set_status("WARNUNG", "yellow")).grid(row=0, column=1, padx=2)
tk.Button(button_frame, text="Störung", bg="red", fg="white", width=8,
command=lambda: self.set_status("STÖRUNG", "red")).grid(row=0, column=2, padx=2)
def set_status(self, status_text, color):
self.status = status_text
self.status_label.config(text=f"Status: {status_text}", bg=color)
class AndonBoardApp:
def __init__(self, root):
root.title("Andon Board – 16 Maschinen")
self.frames = []
for i in range(16):
frame = MachineFrame(root, i + 1)
frame.grid(row=i // 4, column=i % 4, padx=5, pady=5, sticky="nsew")
self.frames.append(frame)
# Optionale: Fenstergröße anpassen
for i in range(4):
root.columnconfigure(i, weight=1)
root.rowconfigure(i, weight=1)
if __name__ == "__main__":
root = tk.Tk()
root.geometry("1000x700")
app = AndonBoardApp(root)
root.mainloop()
----------------------------------------------------------------
Was muss ich jetzt bei PiCtory genau machen, dass ich mein Programm per Knopfdruck ausführen kann.
Bitte entschuldigt diese für einige simple Frage, aber ich bin noch sehr frisch in diesem Thema und blicke bei PiCtory noch nicht durch.
Gruß Ole
ich versuche aktuell ein Andon System zu erstellen, sprich wenn ich auf eine Taste drücke, soll sie Rot, Gelb oder Grün anzeigen. Mein Programm ist in Python geschrieben. Ich habe ein fertiges Bedienfeld und dieses mit meinem RevPi Connect 5 mit DIO Modul verbunden. Jetzt verstehe ich jedoch nicht genau, was ich in PiCtory machen muss, damit sich die Farbe in meinem Programm per Knopfdruck verändert. Ich bin leider relativ neu in der Materie und blicke noch nicht ganz durch.
Dies ist mein Programm als Code:
import tkinter as tk
class MachineFrame(tk.Frame):
def __init__(self, master, machine_id):
super().__init__(master, bd=2, relief="groove", padx=5, pady=5)
self.machine_id = machine_id
self.status = "OK"
# Titel
self.label = tk.Label(self, text=f"Maschine {machine_id}", font=("Arial", 12, "bold"))
self.label.pack(pady=5)
# Status-Anzeige
self.status_label = tk.Label(self, text=f"Status: {self.status}", bg="green", fg="white", width=40, height=3, font=("Arial", 10))
self.status_label.pack(pady=5)
# Button-Gruppe
button_frame = tk.Frame(self)
button_frame.pack()
tk.Button(button_frame, text="OK", bg="green", fg="white", width=8,
command=lambda: self.set_status("OK", "green")).grid(row=0, column=0, padx=2)
tk.Button(button_frame, text="Warnung", bg="yellow", fg="black", width=8,
command=lambda: self.set_status("WARNUNG", "yellow")).grid(row=0, column=1, padx=2)
tk.Button(button_frame, text="Störung", bg="red", fg="white", width=8,
command=lambda: self.set_status("STÖRUNG", "red")).grid(row=0, column=2, padx=2)
def set_status(self, status_text, color):
self.status = status_text
self.status_label.config(text=f"Status: {status_text}", bg=color)
class AndonBoardApp:
def __init__(self, root):
root.title("Andon Board – 16 Maschinen")
self.frames = []
for i in range(16):
frame = MachineFrame(root, i + 1)
frame.grid(row=i // 4, column=i % 4, padx=5, pady=5, sticky="nsew")
self.frames.append(frame)
# Optionale: Fenstergröße anpassen
for i in range(4):
root.columnconfigure(i, weight=1)
root.rowconfigure(i, weight=1)
if __name__ == "__main__":
root = tk.Tk()
root.geometry("1000x700")
app = AndonBoardApp(root)
root.mainloop()
----------------------------------------------------------------
Was muss ich jetzt bei PiCtory genau machen, dass ich mein Programm per Knopfdruck ausführen kann.
Bitte entschuldigt diese für einige simple Frage, aber ich bin noch sehr frisch in diesem Thema und blicke bei PiCtory noch nicht durch.
Gruß Ole