if button == 'deactivate': window['activate'].Update(button_color=('white', '#082567')) window['deactivate'].Update(disabled=True) window.Refresh() if thread_weight: thread_weight.kill() if button == 'clean': window['Textbox'].Update('') window['Textbox2'].Update('') window.Refresh() if button == 'exit': if sg.PopupOKCancel('Deseja mesmo sair???', title="Sair", location=(width // 2 + x - 100, height // 2 + y - 100) ) == "OK": if thread_weight: thread_weight.kill() time.sleep(2) window.close() quit() if not is_server and not is_remote_port: window['Textbox2'].Update(f'{get_current_weight(settings=settings)} KG') else: weight = get_weight_network(serial_port) window['Textbox'].Update(get_balance_info()) window['Textbox2'].Update(f'{weight["message"]} KG') window['last_weight'].Update(get_last_weight()) window.Refresh() window.close()
comPorts, comPort = getSerialPorts() ser = serial.Serial(comPort, 9600) arduinoConnected = True except: # Automatic Arduino COM port detection failed so giving the user the possibility to manually enter the COM port comPort = sg.PopupGetText(('Connect your Arduino and enter Arduino COM port!\nAvailable hardware COM ports are:\n' + str(comPorts[0])), 'Enter COM port') comPorts = [], [] if comPort == "Cancel" or comPort is None: exit() try: # Try to connect to the manually specified COM port ser = serial.Serial(comPort, 9600) arduinoConnected = True except: # Manual input of the COM port failed so giving the user the possibility to try again or leave decision = sg.PopupOKCancel("The COM port you entered is not available.\nClick OK to try again or Cancel to exit!") if decision == "Cancel" or decision is None: exit() # **************************************** Defines the GUI ***************************************************************************************************** # layout = [ [sg.Text('Select RGB LED color...')], [sg.Button('RED', button_color = ("white", "red"), key='red', size=(207,40)), sg.Button('GREEN', button_color = ("white", "green"), key='green', size=(207,40))], [sg.Button('BLUE', button_color = ("white", "blue"), key='blue', size=(207,40)), sg.Button('PURPLE', button_color = ("white", "purple"), key='purple', size=(207,40))], [sg.Text('_' * lineLength)], [sg.ColorChooserButton("", button_color=sg.TRANSPARENT_BUTTON, image_filename="rgb.png", image_subsample=2, size=(207, 40), border_width=0, key="rgbSelect"), sg.Button('Apply selected color', size=(207,40), key="apply"), ], [sg.Text('_' * lineLength)], [sg.Button('LED off', size=(207,40), key='Off'), sg.Button('Exit', size=(207,40), key='exit')],