ich hab ein größeres Programm, möchte aber nun das Hauptcode im File FW.py von der GUI trennen.
Nun sind die Touchscreen-Buttons aber an Funktionen aus dem Hauptfile (FW.py) gebunden, die nun nicht mehr in dem Modul gefunden werden können, wie hier z.B. self.repeat.
GUI:
Code: Alles auswählen
self.button_repeat = tk.Button(self.root, command=self.repeat)
Code: Alles auswählen
class Gui(Controls):
def __init__(self, class_Control):
Wie schaffe ich es, dass die ausgelagerten Buttons der GUI Funktionen aus dem Hauptprogramm aufrufen?
Hier der gesamte Code:
Code: Alles auswählen
""" GUI for touch screen display"""
import tkinter as tk
from PIL import ImageTk
class Gui():
my_color = {'green': '#00A587', 'grey': '#425583', 'limeblue': '#8DC8E8', 'orange': '#FF6A39', 'yellow': '#D0DF00'} # Dictionary of color theme
def __init__(self, class_Control):
"""initialize parameters"""
self.class_Control = class_Control
self.root = tk.Tk()
self.root.geometry("800x480")
self.root.attributes('-fullscreen', True)
self.root.bind('<Return>', self.get_input_and_check)
self.root.bind('<F12>', self.quit)
self.seriallabel_text = tk.StringVar() # Binding variable to display serial number
self.statuslabel_text = tk.StringVar() # Binding variable to display status message
self.label_serialnumber = tk.Label(self.root, textvariable=self.seriallabel_text)
self.label_serialnumber.config(font=('Arial, 24'), justify='center', background='white',
fg=self.my_color['grey'], borderwidth=1, relief="solid")
self.label_serialnumber.place(x=231, y=0, width=569, height=230)
self.label_status = tk.Label(self.root, textvariable=self.statuslabel_text)
self.label_status.config(font=('Arial', 24), justify='center', background="white", fg=self.my_color['grey'],
borderwidth=1, relief="solid")
self.label_status.place(x=231.00, y=230, width=569, height=230)
# Create buttons and add button pictures
self.bild = ImageTk.PhotoImage(file="images/repeat_button.bmp")
self.button_repeat = tk.Button(self.root, command=self.repeat)
self.button_repeat.configure(image=self.bild, borderwidth=1)
self.button_repeat.place(x=0.0, y=0, width=230, height=230)
self.button_mode_switch = tk.Button(self.root, command=self.modeswitch)
self.button_mode_switch.configure(text="Manual\nmode", font=('Arial', 20), borderwidth=1,
bg=self.my_color['limeblue'], activebackground=self.my_color['limeblue'])
self.button_mode_switch.place(x=0.0, y=345, width=230, height=115)
self.root.title("Display")
self.seriallabel_text.set("Please connect")
self.message = "blabla"
self.statuslabel_text.set(self.message)