When I print the list that I am setting the Combobox to I am getting an updated list based on the available com ports, however the values in the drop down box are not working. I have a feeling that it is because I am using customtkinter.... I really hope not. Does anyone see what is happening here?
import customtkinter
from ConnexLink import findcomports, recievesignal, closeserialport
import serial
customtkinter.set_appearance_mode("light") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
app = customtkinter.CTk()
app.geometry("500x500")
app.title("Connex Link")
def runfindcomports(afterfirstrun=True):
ports=[]
for info in serial.tools.list_ports.comports():
port1=str(info)#sets the com port to port1
ports.append(port1[0:4])
if afterfirstrun:
combobox_1['values']=ports
print('why is it not working')
print(ports)
return(ports)
ports=runfindcomports(False)
onoroff = False
def onswitch():
global onoroff
global ser
if onoroff:
onoroff=False
ser.close()
else:
onoroff=True
print('on')
ser = serial.Serial(combobox_1.get(),9600,timeout=2) # open serial port
frame_1 = customtkinter.CTkFrame(master=app)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=customtkinter.LEFT,text='Vibrac')
label_1.pack(pady=10, padx=10)
combobox_1 = customtkinter.CTkComboBox(frame_1)
combobox_1.pack(pady=10, padx=10)
combobox_1.set("Select Com Port")
combobox_1['values']=ports
switch_1 = customtkinter.CTkSwitch(master=frame_1, command=onswitch,text='receive',)
switch_1.pack(pady=10, padx=10)
button_1 = customtkinter.CTkButton(master=frame_1, command=runfindcomports,text='refresh',)
button_1.pack(pady=10, padx=10)
text_1 = customtkinter.CTkTextbox(master=frame_1, width=300, height=300)
text_1.pack(pady=10, padx=10)
def textfilter(bytes):
text=str(bytes)
text=text[2:]
text=text.split('\\',1)[0]
return text
def printline():
global onoroff
if onoroff:
line = ser.readline()
if len(line) > 2:
text_1.insert("end",textfilter(line)+'\n')
app.after(500,printline)
app.after(500,printline)
app.mainloop()
It's a bug in CustomTkinter library. You can use configure()
instead of __setitem__
like this.
combobox_1.configure(values=ports)
What about reporting this here?
I'm not a CTk user or developer, but I analyzed the bug. The parameter lists of the configure()
methods of the CTk widgets do not conform to the convention of the tkinter base class, as you can see in this and this.