该变量ports_available
包含一个 COMPORTS 数组。我希望在 GUI 启动时将这些添加到子菜单“ports_menu”中,以便我可以选择其中任何一个来选择 COMPORT。
global ports_available
ports_available = [comport.device for comport in serial.tools.list_ports.comports()]
global port_select
port_select = "COM1"
#Create Menu
my_menu = Menu(window)
window.config(menu = my_menu)
# Add Tool Menu
tool_menu = Menu(my_menu, tearoff = False)
my_menu.add_cascade(label = "Tools", menu = tool_menu)
tool_menu.add_command(label = "Bold", command =bold_it)
tool_menu.add_command(label = "Italic", command =italic_it)
#Menu for ports
ports_menu = Menu(tool_menu, tearoff = False)
tool_menu.add_cascade(label = "Ports", menu = ports_menu)
for name in ports_available:
ports_menu.add_checkbutton(label = name, variable = port_select)
[![When i select any one of the option everything gets selected][1]][1]
谢谢你,德鲁夫·古普塔