1

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()
relent95
  • 3,703
  • 1
  • 14
  • 17
koorn5
  • 21
  • 3
  • 1
    Is it possible for you to rewrite your example to use some hard-coded data rather than relying on the `serial` and `ConnexLink` modules? – Bryan Oakley Mar 09 '23 at 22:14
  • 1
    What exactly do you mean by "not working"? Are the ports not appearing in the combobox at all, or is there some problem when you select them from the list? (I'm rather suspicious of the code involving `port1[0:4]` - that cannot possibly work if the name of the port is of a different length.) – jasonharper Mar 09 '23 at 22:18
  • You always have afterfirstrun=False. – Сергей Кох Mar 10 '23 at 00:07
  • https://customtkinter.tomschimansky.com/documentation/widgets/combobox – Clive Bostock Jul 15 '23 at 00:31

1 Answers1

1

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.

relent95
  • 3,703
  • 1
  • 14
  • 17
  • Not sure I would describe that as a CustomTkinter bug. The code in the question appears to be where the bug lies: combobox_1['values']=ports – Clive Bostock Jul 03 '23 at 07:37
  • @CliveBostock, what do you mean? The ```combobox_1['values']=ports``` calls ```CTkComboBox.configure({'values': ports})``` and the ```CTkComboBox.configure()``` does not get the ```values``` as a keyword argument because it gets ```{'values': ports}``` as the ```require_redraw``` argument. I'm VERY CERTAIN it's a CustomTkinter bug. – relent95 Jul 03 '23 at 09:10
  • Check the syntax for assigning values: https://customtkinter.tomschimansky.com/documentation/widgets/combobox – Clive Bostock Jul 15 '23 at 00:32
  • I know that. I'm saying ```CTKComboBox``` should follow the Tkinter convention. See [this](https://docs.python.org/3/library/tkinter.html#setting-options). – relent95 Jul 15 '23 at 06:44
  • If CustomTkinter behaves according to the CustomTkinter docs, then, it can't be described as a *bug* in CustomTkinter. – Clive Bostock Jul 17 '23 at 12:51