From ac6546d0fc39b4e5d223aa67357bd384c13cf216 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Sun, 7 Jul 2024 21:56:44 +0800 Subject: [PATCH] first commit --- .gitignore | 2 ++ requirements.txt | 2 ++ src/main.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100644 src/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb6f3e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv/ +src/__pycache__/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..447bace --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pip==24.1.1 +setuptools==65.5.0 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..640fefc --- /dev/null +++ b/src/main.py @@ -0,0 +1,67 @@ +import customtkinter as ctk + +import serial +import serial.tools.list_ports as ls_ports + +from typing import Optional + + +class App(ctk.CTk): + __window_width = 1280 + __window_height = 720 + __column_weight = [1, 5] + + def __init__(self) -> None: + super().__init__() + self.__windowInit(self.__window_width, self.__window_height) + + def __windowInit(self, width: int, height: int) -> None: + self.title("ISP上位机") + # appearance and font + ctk.set_appearance_mode("dark") + ctk.set_default_color_theme("dark-blue") + ctk.set_widget_scaling(2.0) + self.font = ctk.CTkFont(family="", size=17) + + # get the screen dimension + screen_width = self.winfo_screenwidth() + screen_height = self.winfo_screenheight() + # find the center point + center_x = int(screen_width / 2 - width / 2) + center_y = int(screen_height / 2 - height / 2) + # set the position of the self to the center of the screen + self.geometry(f"{width}x{height}+{center_x}+{center_y}") + # seperate the column + self.columnconfigure(0, weight=self.__column_weight[0]) + self.columnconfigure(1, weight=self.__column_weight[1]) + + # create label + self.serial_label = ctk.CTkLabel(self, text="串口:", font=self.font) + self.serial_label.grid(column=0, row=1, sticky=ctk.EW) + # create combobox + self.serial_combobox = ctk.CTkComboBox( + self, + state="readonly", + command=self.updateSerial, + font=self.font, + dropdown_font=self.font, + ) + self.serial_combobox.bind() + self.updateSerial() + self.serial_combobox.grid(column=1, row=1, sticky=ctk.EW) + return None + + def updateSerial(self, port_info: Optional[str] = None): + port_list = [] + for info in ls_ports.comports(): + port, desc, hwid = info + port_list.append(port + " " + desc) + self.serial_combobox.configure(values=port_list) + + def run(self): + self.mainloop() + + +if __name__ == "__main__": + app = App() + app.run()