Tkinter drop down list of check-boxes/combo-boxes
Asked Answered
D

2

16

I am attempting to create a post-processing data application in Python, and I am designing the GUI for this using Tkinter.

I do not know if Tkinter supports a drop down list composed of check boxes, of which you can then select multiple boxes from. The picture below reflects what I am attempting to describe:

enter image description here

Is this possible?

Dugger answered 18/11, 2015 at 13:12 Comment(2)
Why are you trying to do this? Just wondering...Ardel
Essentially, one of the options the user should be able to select from is "Site" (e.g. Site A, Site B, Site C, Site D), so I would like for the user to be able to select which site/sites they want to view the data for from the above optionsDugger
U
6

Its not exactly what you wanted, but hope it helps.

from Tkinter import *

top = Tk()

mb=  Menubutton ( top, text="CheckComboBox", relief=RAISED )
mb.grid()
mb.menu  =  Menu ( mb, tearoff = 0 )
mb["menu"]  =  mb.menu

Item0 = IntVar()
Item1 = IntVar()
Item2 = IntVar()

mb.menu.add_checkbutton ( label="Item0", variable=Item0)
mb.menu.add_checkbutton ( label="Item1", variable=Item1)
mb.menu.add_checkbutton ( label="Item2", variable=Item2)


'''This part is only for testing
def Item_test():
    if Item0.get() == True:
        print "Item0 True"
    elif Item0.get() == False:
        print "Item0 False"
    else:
        print Item0.get()
    if Item1.get() == True:
        print "Item1 True"
    elif Item1.get() == False:
        print "Item1 False"
    else:
        print Item1.get()
    if Item2.get() == True:
        print "Item2 True"
    elif Item2.get() == False:
        print "Item2 False"
    else:
        print Item2.get()

button1 = Button(top, text="Item True/False Test", command = Item_test)
button1.pack()
''' 

mb.pack()
top.mainloop()
Uncaused answered 11/2, 2016 at 21:47 Comment(4)
This isn't Python3 compatible, but can be with some simple fixes to import and print statements. Also, you mixed pack and Grid which fails. Change every occurrence of grid() to pack() and it works fine. Otherwise thanks for this! Was just what I was looking for!Seepage
For me, I had to change the case of Tkinter to lowercase like this to make it work (Python 3.9.5). from tkinter import *Salvo
The checkboxes are not nice and clear like in the questionWame
it is great. Maybe it doesn't look as nicely as in the question, but the solution is very compact and does the job just fine.Inviolable
L
4

I became a bit obsessed with this problem and subsequently spent some time trying to solve it. I think I came up with a pretty decent solution -- or at least the beginnings of a pretty decent solution. If you do use this code and run into any bugs or issues, please do let me know by posting an "Issue" on the GitHub page.

https://github.com/hatfullr/ChecklistCombobox

Lamond answered 23/11, 2020 at 2:14 Comment(1)
Thanks for the pointer - your solution looks like a good start for me. The PyPI packaging seems to have gone slightly awry, I'll try to make some contributions to that as I think I will use your implementation as a base for something I'm working on.Aposematic

© 2022 - 2024 — McMap. All rights reserved.