Scrollbar tkinter checkbutton

76 views Asked by At

I want to display checkbutton with a scrollbar. demo

I would like both buttons to be always visible (that the scrollbar is only on the checkbutton)

Here is my code:

def selectColumns(self, data):
        new_window = Toplevel(self.master, height=400, width=200)
        select = Button(new_window, text="select all", command=lambda: self.selection_all(list_var))
        select.pack()
        
        canvas = Canvas(new_window, bg='#FFFFFF', width=300, height=300, scrollregion=(0, 0, 500, 500))
        canvas.pack(side=LEFT)
        
        vbar = Scrollbar(new_window, orient=VERTICAL)
        vbar.config(command=canvas.yview)
        vbar.pack(side=RIGHT)
        
        frame = Frame(new_window, borderwidth=3, relief="sunken", bg="red", height=300, width=200)
        canvas.create_window(0, 0, anchor=NW, window=frame)
        
        i = 1
        list_var = []
        for col in data.columns:
            var = BooleanVar()
            # var.set(True)
            list_var.append((var, col))
            check = Checkbutton(frame, text=col, variable=var).pack()
            i += 1
        valid = Button(new_window, text="Valid", command=lambda: self.getValue(list_var, data=data, win=new_window))
        valid.pack()

encountered problem:

  • My checkbutton sticks out of my canvas
  • My valid button is not aligned How to do with pack (), so that the canva is on the left, the scrollbar on the right and my valid button at the bottom centered?
0

There are 0 answers