Search code examples
pythonlisttkintercombobox

python tkinter strange { in list


I'm straggling with this {} in selection section. I'm having trouble even within selectionbox. It happens only with the spaces in list.

import tkinter as tk
from tkinter import ttk

all_users = [(7, 'Analize space me'), (8, 'Analize space me2'), 
    (9, 'And more')]

main_window = tk.Tk()
main_window.config(width=300, height=200)
main_window.title("Combobox")
combo = ttk.Combobox(values=all_users,width=35)

combo.place(x=50, y=50)
main_window.mainloop()

enter image description here


Solution

  • It is added by the underlying TCL interpreter. You need to convert the list of tuples into list of strings before passing it to ttk.Combobox(...):

    ...
    values = [f"{x}: {y}" for x, y in all_users]
    combo = ttk.Combobox(values=values, width=35)
    ...