2

我想显示带有滚动条的检查按钮。 演示

我希望两个按钮始终可见(滚动条仅在复选按钮上)

这是我的代码:

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()

遇到的问题:

  • 我的检查按钮伸出我的画布
  • 我的有效按钮未对齐如何处理pack(),使canva在左侧,滚动条在右侧,我的有效按钮在底部居中?
4

0 回答 0