praca
unknown
plain_text
2 years ago
16 kB
1
Indexable
Never
import tkinter as tk from tkinter import * from tkinter import ttk, messagebox from functools import partial from datetime import datetime # from ramka import * # import serial # ser = serial.Serial('COM4', 19200, 8, 'N', 1) LARGE_FONT = ("Roboto", 12) MID_FONT = ("Roboto", 9) buttonIconOnOff = [False, False, False, False, False, False, False, False] lista = [[None, None] for _ in range(8)] class Application(tk.Tk): WIDTH = 780 HEIGHT = 520 def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) tk.Tk.wm_title(self, "OUT Menager") self.geometry(f"{Application.WIDTH}x{Application.HEIGHT}") self.resizable(False, False) container = tk.Frame(self) container.grid(column=0, row=0, sticky='nsew') self.frames = {} for F in (StartPage, PageOne): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StartPage) def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() def qf(): print("done") class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(1, weight=1) self.grid_columnconfigure(0, weight=4) self.grid_columnconfigure(1, weight=1) outs_frame = tk.LabelFrame(self, height=500, width=620, text=' STEROWANIE WYJSCIAMI ', font=LARGE_FONT ) outs_frame.grid_propagate(False) outs_frame.grid(row=0, rowspan=2, column=0, sticky='', ipadx=12, padx=10, pady=10) outs_frame.grid_rowconfigure(0, weight=1) outs_frame.grid_rowconfigure(1, weight=1) outs_frame.grid_columnconfigure(0, weight=1) outs_frame.grid_columnconfigure(1, weight=1) outs_frame.grid_columnconfigure(2, weight=1) outs_frame.grid_columnconfigure(3, weight=1) right_bar = ttk.Frame(self, width=140, height=520) right_bar.grid(row=0, rowspan=2, column=1, sticky='nsew') right_bar.grid_propagate(False) self.buttonIconCfg = tk.PhotoImage(file='UI/images/cfg.png') button1 = ttk.Button(master=right_bar, text="OUT CFG", image=self.buttonIconCfg, compound='bottom', command=lambda: controller.show_frame(PageOne)) button1.grid(row=0, column=0, sticky='', pady=20) buttonIconOff = tk.PhotoImage(file='UI/images/bulboff2.png') buttonIconOn = tk.PhotoImage(file='UI/images/bulbon2.png') buttonIcon = buttonIconOff def button1click(): if (bulb_button1['text'] == 'Off'): bulb_button1['text'] = 'On' bulb_button1['image'] = buttonIconOn today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") print("co pokaze today?:", dt_string) x = '$FE$FE$88$11$11$FF$FF$FF$FF$FF$FF$01$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$C6$1F$FE$0D' komenda = x.replace('$', '') print("test dupa: ", lista) #hexString = komenda #byte_array = bytearray.fromhex(hexString) #ser.write(byte_array) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button1['text'] = 'Off' bulb_button1['image'] = buttonIconOff x = '$FE$FE$89$11$11$FF$FF$FF$FF$FF$FF$01$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$C0$67$FE$0D' komenda = x.replace('$', '') print("test dupa: ", lista) #hexString = komenda #byte_array = bytearray.fromhex(hexString) #ser.write(byte_array) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button2click(): if (bulb_button2['text'] == 'Off'): bulb_button2['text'] = 'On' bulb_button2['image'] = buttonIconOn x = '$FE$FE$88$11$11$FF$FF$FF$FF$FF$FF$02$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$59$A7$FE$0D' komenda = x.replace('$', '') print("test dupa: ", lista) #hexString = komenda #byte_array = bytearray.fromhex(hexString) #ser.write(byte_array) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button2['text'] = 'Off' bulb_button2['image'] = buttonIconOff x = '$FE$FE$89$11$11$FF$FF$FF$FF$FF$FF$02$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$6C$1C$FE$0D' komenda = x.replace('$', '') print("test dupa: ", lista) #hexString = komenda #byte_array = bytearray.fromhex(hexString) #ser.write(byte_array) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button3click(): if (bulb_button3['text'] == 'Off'): bulb_button3['text'] = 'On' bulb_button3['image'] = buttonIconOn x = '$FE$FE$91$11$11$FF$FF$FF$FF$FF$FF$03$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$0D$56$FE$0D' komenda = x.replace('$', '') print("test dupa: ", lista) #hexString = komenda #byte_array = bytearray.fromhex(hexString) #ser.write(byte_array) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button3['text'] = 'Off' bulb_button3['image'] = buttonIconOff x = '$FE$FE$91$11$11$FF$FF$FF$FF$FF$FF$03$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$00$0D$56$FE$0D' komenda = x.replace('$', '') print("test dupa: ", lista) #hexString = komenda #byte_array = bytearray.fromhex(hexString) #ser.write(byte_array) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button4click(): if (bulb_button4['text'] == 'Off'): bulb_button4['text'] = 'On' bulb_button4['image'] = buttonIconOn print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button4['text'] = 'Off' bulb_button4['image'] = buttonIconOff print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button5click(): if (bulb_button5['text'] == 'Off'): bulb_button5['text'] = 'On' bulb_button5['image'] = buttonIconOn print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button5['text'] = 'Off' bulb_button5['image'] = buttonIconOff print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button6click(): if (bulb_button6['text'] == 'Off'): bulb_button6['text'] = 'On' bulb_button6['image'] = buttonIconOn print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button6['text'] = 'Off' bulb_button6['image'] = buttonIconOff print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button7click(): if (bulb_button7['text'] == 'Off'): bulb_button7['text'] = 'On' bulb_button7['image'] = buttonIconOn print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button7['text'] = 'Off' bulb_button7['image'] = buttonIconOff print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") def button8click(): if (bulb_button8['text'] == 'Off'): bulb_button8['text'] = 'On' bulb_button8['image'] = buttonIconOn print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") else: bulb_button8['text'] = 'Off' bulb_button8['image'] = buttonIconOff print("test dupa: ", lista) today = datetime.now() dt_string = today.strftime("%d/%m/%Y %H:%M:%S") bulb_button1 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button1click) bulb_button1.grid(row=0, column=0, sticky='') bulb_button2 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button2click) bulb_button2.grid(row=0, column=1, sticky='') bulb_button3 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button3click) bulb_button3.grid(row=0, column=2, sticky='') bulb_button4 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button4click) bulb_button4.grid(row=0, column=3, sticky='') bulb_button5 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button5click) bulb_button5.grid(row=1, column=0, sticky='') bulb_button6 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button6click) bulb_button6.grid(row=1, column=1, sticky='') bulb_button7 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button7click) bulb_button7.grid(row=1, column=2, sticky='') bulb_button8 = ttk.Button(master=outs_frame, text='Off', image=buttonIcon, compound=tk.BOTTOM, command=button8click) bulb_button8.grid(row=1, column=3, sticky='') class PageOne(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.outs_cfg_frame = tk.LabelFrame(self, height=500, width=620, text=' USTAWIENIA WYJŚCIA ', font=LARGE_FONT ) self.outs_cfg_frame.grid_propagate(False) self.outs_cfg_frame.grid(row=0, rowspan=2, column=0, sticky='', ipadx=12, padx=10, pady=10) self.outs_cfg_frame.grid_rowconfigure(0, weight=1) self.outs_cfg_frame.grid_rowconfigure(1, weight=1) self.outs_cfg_frame.grid_rowconfigure(2, weight=1) self.outs_cfg_frame.grid_columnconfigure(0, weight=1) self.outs_cfg_frame.grid_columnconfigure(1, weight=1) self.nr_button = tk.LabelFrame(master=self.outs_cfg_frame, text=' KONFIGURACJA PRZYCISKU ', font=MID_FONT, labelanchor='n') self.nr_button.grid(row=0, column=1, sticky='nsew', padx=10, pady=10) vlist = {"OUT_1": 0, "OUT_2": 1, "OUT_3": 2, "OUT_4": 3, "OUT_5": 4, "OUT_6": 5, "OUT_7": 6, "OUT_8": 7} # selected_value = tk.StringVar() Combo = ttk.Combobox(master=self.nr_button, values=list(vlist.keys())) Combo.set("WYBIERZ PRZYCISK") def get_selected_value(): selected_value = Combo.get() global zmienna zmienna = vlist.get(selected_value) print("Wybrana wartość: ", selected_value) # Tworzenie przycisku do wywołania funkcji button = Button(master=self.nr_button, text="Pobierz wybraną wartość", command=get_selected_value) button.grid(row=1, column=0, sticky='', pady=20) Combo.grid(row=0, column=0, sticky='', padx=20, pady=20) self.funkcja = tk.LabelFrame(master=self.outs_cfg_frame, text=' FUNKCJA WYJŚCIA ', font=MID_FONT, labelanchor='n') self.funkcja.grid(row=1, column=1, sticky='nsew', padx=10, pady=10) #akcja---------------------------------------------------------------------------------------------- #akcja = ["ON", "OFF", "STATE SWIT3CH"] akcja = {"ON": 1, "OFF": 0, "STATE SWITCH": 2} # selected_value = tk.StringVar() Combo2 = ttk.Combobox(master=self.funkcja, values=list(akcja.keys())) Combo2.set("WYBIERZ FUNKCJE") def get_selected_value2(): selected_value2 = Combo2.get() test = akcja.get(selected_value2) lista[zmienna][0] = test print("Wybrana wartość: ", selected_value2) # Tworzenie przycisku do wywołania funkcji button2 = Button(master=self.funkcja, text="Pobierz wartość wyjścia", command=get_selected_value2) button2.grid(row=1, column=0, sticky='', pady=20) Combo2.grid(row=0, column=0, sticky='', padx=20, pady=20) self.wyj = tk.LabelFrame(master=self.outs_cfg_frame, text=' WYBIERZ NR WYJŚĆ CENTRALI ', font=MID_FONT, labelanchor='n') self.wyj.grid(row=2, column=1, sticky='nsew', padx=10, pady=10) wyjscia = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] Combo3 = ttk.Combobox(master=self.wyj, values=wyjscia) Combo3.set("WYBIERZ WYJŚCIE") Combo3.grid(row=0, column=0, sticky='NSEW', padx=20, pady=20) def get_selected_value3(): selected_value3 = Combo3.get() lista[zmienna][1] = selected_value3 print("Wybrana wartość: ", selected_value3) # Tworzenie przycisku do wywołania funkcji button3 = Button(master=self.wyj, text="Pobierz wartość wyjścia", command=get_selected_value3) button3.grid(row=1, column=0, sticky='', pady=20) self.IconOn = tk.PhotoImage(file='UI/images/bulbon1.png') out_im = tk.Label(master=self.outs_cfg_frame, image=self.IconOn) out_im.grid(row=0, column=0, rowspan=3, sticky='', padx=20, pady=20) self.right_bar = ttk.Frame(self, width=140, height=520) self.right_bar.grid(row=0, column=1, sticky='nsew') self.buttonIconOUTs = tk.PhotoImage(file='UI/images/bulbon3.png') button1 = ttk.Button(master=self.right_bar, text="OUT's", image=self.buttonIconOUTs, compound='bottom', command=lambda: controller.show_frame(StartPage)) button1.grid(row=0, column=0, sticky='', pady=20) app = Application() app.eval('tk::PlaceWindow . center') app.mainloop()