# This file was generated by the Tkinter Designer by Parth Jadhav
# https://github.com/ParthJadhav/Tkinter-Designer
from pathlib import Path
# from tkinter import *
# Explicit imports to satisfy Flake8
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage
import serial
# Declare ser globally
ser = None
try:
ser = serial.Serial('COM3', 9600) # Replace 'COM_PORT' with the correct port
print("Connecting...")
except Exception as e:
print(f"Error opening serial port: {e}")
ser = None # Ensure ser is defined even if the connection fails
print("Failing...")
def toggle_led():
"""Toggle the state of the LED."""
global ser, led_state
if ser and ser.is_open:
led_state = not led_state # Toggle state between True and False
ser.write(('1' if led_state else '0').encode()) # Send '1' for ON and '0' for OFF
else:
print("Serial port is not available or open.")
# Assume led_state is initially False (LED is off)
led_state = False
OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path(r"C:\Users\Fernanda\OneDrive - Universidad Iberoamericana, Puebla\Escritorio\Tkinter-Designer-master\build\assets\frame0")
def relative_to_assets(path: str) -> Path:
return ASSETS_PATH / Path(path)
window = Tk()
window.geometry("390x844")
window.configure(bg = "#FFFFFF")
canvas = Canvas(
window,
bg = "#FFFFFF",
height = 844,
width = 390,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)
canvas.place(x = 0, y = 0)
button_image_1 = PhotoImage(
file=relative_to_assets("button_1.png"))
button_1 = Button(
image=button_image_1,
borderwidth=0,
highlightthickness=0,
command=toggle_led,
relief="flat"
)
button_1.place(
x=145.0,
y=110.0,
width=100.0,
height=100.0
)
button_image_2 = PhotoImage(
file=relative_to_assets("button_2.png"))
button_2 = Button(
image=button_image_2,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_2 clicked"),
relief="flat"
)
button_2.place(
x=145.0,
y=246.0,
width=100.0,
height=100.0
)
button_image_3 = PhotoImage(
file=relative_to_assets("button_3.png"))
button_3 = Button(
image=button_image_3,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_3 clicked"),
relief="flat"
)
button_3.place(
x=131.0,
y=382.0,
width=121.0,
height=136.0
)
button_image_4 = PhotoImage(
file=relative_to_assets("button_4.png"))
button_4 = Button(
image=button_image_4,
borderwidth=0,
highlightthickness=0,
command=lambda: print("button_4 clicked"),
relief="flat"
)
button_4.place(
x=49.0,
y=642.0,
width=292.0,
height=92.0
)
window.resizable(False, False)
window.mainloop()
1
2
3
4
5
6
7
8
9
10
11
12
14
15
16
13