first commit

This commit is contained in:
SikongJueluo 2024-07-07 21:56:44 +08:00
commit ac6546d0fc
No known key found for this signature in database
GPG Key ID: D2D3D29A993716EA
3 changed files with 71 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.venv/
src/__pycache__/

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pip==24.1.1
setuptools==65.5.0

67
src/main.py Normal file
View File

@ -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()