I want to be able to make multiple selections in the Combobox

I am creating a GUI with Tkinter in Python.

ComboboxI'd like to use (usually stored and a list appears when you press the down arrow button)Select multiple itemsI want to be able to do it.

Does anyone know how to do it?

Source code

↑ The code based on this is shown below.

import tkinter as tk
import tkinter.ttk as ttk
list = ["alpha", "beta", "gamma"]
root = tk.Tk ()
root.title ("Combobox_test")
fra = ttk.Frame (root)
fra.grid ()
v = tk.StringVar ()
cb = ttk.Combobox (fra, textvariable = v, values ​​= list, width = 10)
cb.set (list [0])
cb.bind ("<<ComboboxSelected >>", lambda e: print ("v =% s"% v.get ()))
cb.grid (row = 0, column = 0)
btn = ttk.Button (fra, text = "Button", command = lambda: print ("v =% s"% v.get ()))
btn.grid (row = 0, column = 1)
root.mainloop ()
Supplementary information (FW/tool version, etc.)

Windows 10
Python 8.3.8
tk 8.6.10

  • Answer # 1

    If you want to select more than one, I think the easiest one is Listbox.
    Create a Listbox with height = 1, place it so that a small button "▼" etc. is attached next to the Listbox, and increase the height of the Listbox/return it to 1 every time it occurs in a click event. How about making it as a target?

  • Answer # 2

    ttk.Combobox does not support multiple selection.

    Since the input part of the Combobox is Entry, it can only have a single value.
    If you want to express multiple values, you need to take measures such as separating them with something.

    The list that appears when you press the arrow uses Listbox
    Listbox itself-selectmode multipleYou can select more than one by specifying,
    There is no way to pass options.

    If you can make multiple selections,
    With a Combobox, you'll have trouble typing directly.
    (Therefore, most GUI combo boxes do not support multiple selection)

    If you don't need direct input
    Build a widget for multiple selection in Listbox.

    If you want to add an arbitrary value by direct input,
    Display the Listbox in a dialog or pop-up
    There will be a column for adding selection items to the list.