import customtkinter as ctk import messagebox import serial import serial.tools import serial.tools.list_ports as ls_ports from typing import Optional, Any import functools class App(ctk.CTk): __window_width = 1280 __window_height = 1350 __column_weight = [1, 9, 3] serial_status = False serial_baudrate = 9600 gain_default = [1.30, 0.70, 1.10, 2.20, 0.50] gain_values = gain_default.copy() gain_values_store = gain_default.copy() gain_enable = [True for i in range(5)] def __init__(self) -> None: super().__init__() self.__windowInit(self.__window_width, self.__window_height) self.__data_frame() 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") self.font = ctk.CTkFont(family="", size=17) # get the screen dimension screen_width = self.winfo_screenwidth() screen_height = self.winfo_screenheight() # high dpi support if screen_width >= 3840 and screen_height >= 2160: ctk.set_widget_scaling(2.0) messagebox.isHighDIP = True else: ctk.set_window_scaling(0.8) # 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}") # create gain_frame top_frame = ctk.CTkFrame(self) top_frame.pack(side="top", fill=ctk.X, padx=10) top_frame.columnconfigure(0, weight=self.__column_weight[0]) top_frame.columnconfigure(1, weight=self.__column_weight[1]) top_frame.columnconfigure(2, weight=self.__column_weight[2]) # Serial Port # create label self.serial_label = ctk.CTkLabel(top_frame, text="串口:", font=self.font) self.serial_label.grid(column=0, row=0, sticky=ctk.EW, pady=10, padx=10) # create combobox self.serial_combobox = ctk.CTkComboBox( top_frame, state="readonly", command=self.selectSerial, font=self.font, dropdown_font=self.font, ) self.serial_combobox.bind("