0

复选框的滚动条不起作用我已经实现了列表框和复选框,我想一次滚动它们

def startButton(self):

frame = tk.Frame(self.root, width=1110, height=552)
frame.place(x=10, y=69)
frame.configure(background="light gray")

# Diplay 1st Column Area
listbox = tk.Listbox(frame, width=50, height=26,font=('Times New Roman', 13))
listbox.place(x=5, y=5)

scroll_y = tk.Scrollbar(frame,orient = 'vertical')
scroll_y.place(x = 457, y = 5, height = 542)
scroll_y.config(command = listbox.yview)

scroll_x = tk.Scrollbar(frame, orient = 'horizontal')
scroll_x.place(x = 5, y = 530, width = 454)
scroll_x.config(command = listbox.xview)

# Diplay Checkbox
widget = scrolledtext.ScrolledText(frame, width=28, height=33)
widget.place(x=480, y=5)
widget.configure(background="light gray")


data = {}
ID = []

with open(self.filename) as f:
    reader = csv.DictReader(f, delimiter=',')

    for row in reader:
            if row['column1']:
                key = row['column1']
                data[key] = []
            data[key].append(row['Result'])

    posX = 10
    posY = 0
    myCheckBoxfont = ('Arial Bold', 8)
    i=0

    for item in data[key]:
        listbox.insert('end', item)

        chk_state = tk.IntVar()
        self.state = chk_state
        if item != "":
            cb = tk.Checkbutton(widget, text='PASS', variable=chk_state,
                 onvalue= 1, font=myCheckBoxfont, command=lambda i=i:
                 self.onCheckButton(i)).place(x=posX, y=posY)
        posY += 20
        i += 1
        widget.window_create('end', window=cb)
        widget.insert('end', '\n')
    widget['state'] = 'disabled'

我尝试了什么,我设计了一个框架,并在一个框架上创建了一个列表框,并且 ScrolledText On scrollText 复选框已实现功能工作正常。现在需要复选框和列表框应该只在一个滚动条上工作

删除的列表框添加了一个用于插入项目和复选框的滚动文本

    widget = scrolledtext.ScrolledText(frame, width=40, height=26)
    widget.place(x=5, y=5)
    widget.configure(background="yellow")

for item in data[key]:
    widget.insert('end', item)

    chk_state = tk.IntVar()
    self.state = chk_state
    if item != "":
        cb = tk.Checkbutton(widget, text='Text1', variable=chk_state,
             onvalue= 1, font=myCheckBoxfont, command=lambda i=i:
             self.onCheckButton(i)).place(x=posX, y=posY)
        cb = tk.Checkbutton(widget, text='TExt2', variable=chk_state,
             onvalue= 1, font=myCheckBoxfont, command=lambda i=i:
             self.onCheckButton(i)).place(x=posX+10, y=posY)
        cb = tk.Checkbutton(widget, text='TExt23', variable=chk_state,
             onvalue= 1, font=myCheckBoxfont, command=lambda i=i:
             self.onCheckButton(i)).place(x=posX+20, y=posY)
    posY += 20
    i += 1
    widget.window_create('end', window=cb)
    widget.insert('end', '\n')
widget['state'] = 'disabled'

如果删除 cb.place 如果不显示其他 checkbuttons ,则只有最后一个 checkutton 可见且滚动条不可见

4

0 回答 0