2

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?
Eolynas
  • 43
  • 4
  • Since your checkbuttons are stacked vertically, using a text widget rather than a canvas would be easier. Are you interested in seeing that solution? – Bryan Oakley Oct 02 '20 at 13:45

0 Answers0