Home>
I want to display any number of check buttons

I want to display any number of check buttons.
If I want to display it, if there are three or more, I want to see it without scrolling the scroll bar.
Any number is expected to be 1 to 2 digits low.

Expected output (AA)

┏┓
┃┃☑aaaaaaaaa
┃┃☑ bbbbbbbbb
┗┛☑ccccccccc

Su
Ku
B
-
Le
Ba
-

I want to put the scroll bar on the right. (Although it is on the left in the picture)

  • Answer # 1

    Please refer to it only.

    var_lst = []
    cb_lst = []
    #Enter the number of check boxes you want to make
    create_num = ttk.Entry (root)
    create_num.grid ()
    # Framework to apply check box
    frame = ttk.Frame (root)
    frame.grid ()
    def create_cb ():
        i = int (create_num.get ())
        reset ()
        Prepare #booleanvar for i
        var_lst = [BooleanVar () for var in range (i)]
        #Set default = False to the prepared boolean var
        [var.set (False) for var in var_lst]
        #Set a prepared boolean var to generate a checkbox and store it in the list
        cb_lst = [ttk.Checkbutton (frame, variable = var_lst [cb], text = 'check button') for cb in range (i)]
        # Place the generated check box in the frame
        [wset.grid (row = enum) for enum, wset in enumerate (cb_lst)]
    #Initialization
    def reset ():
        for w in cb_lst:
            w.grid_forget ()
        del var_lst

    Below is how to install the scroll bar.
    Please refer to it.
    https://python.keicode.com/advanced/tkinter-widget-text.php