first commit
This commit is contained in:
commit
ac6546d0fc
|
@ -0,0 +1,2 @@
|
||||||
|
.venv/
|
||||||
|
src/__pycache__/
|
|
@ -0,0 +1,2 @@
|
||||||
|
pip==24.1.1
|
||||||
|
setuptools==65.5.0
|
|
@ -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()
|
Loading…
Reference in New Issue