0

scrollbar for checkbox not working I have listbox and checkbox implemented and i want to scroll both of them at a time

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'

What i tried , I have design one frame and On a frame created one listbox and ScrolledText On scrollText checkbox has implemented functionality is working fine . Now required is the checkbox and Listbox should work on only one scrollbar

Removed listbox added one scrolltext for inserting item and checkbox

    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'

If removed cb.place if does not show other checkbuttons , only last checkutton is visible and scrollbar is not visible

Piu
  • 19
  • 5
  • Why don't you use one `ScrolledText` for both `item` and `cb`? Also `cb = tk.Checkbutton(...).place(...)` will cause `cb` to be `None`. Use `cb = tk.Checkbutton(...)` and don't need to call `cb.place(...)` because `cb` will be put into text box by `.window_create(...)`. – acw1668 Sep 17 '21 at 09:02
  • I tried with ScrolledText , But as per your suggestion i removed cb.place so it does not get align and I have three checkbuttonand i can see only last checkbutton if i removed the place – Piu Sep 20 '21 at 05:22
  • You better add the changed code in your question. – acw1668 Sep 20 '21 at 05:48
  • Why is originally one checkbox (with `text='PASS'`) changed to three checkboxes? BTW you need to call `widget.window_create(...)` on the three checkboxes individually. However using same `IntVar` on the three checkboxes is logically wrong. – acw1668 Sep 20 '21 at 06:27
  • Actually we have three checkbuttnos , and reason for using same IntVar After comming out of the loop I want to check if any of the checkbutton is clicked , and in row it is clicked so that item can displayed with the checkbutton status – Piu Sep 20 '21 at 06:42
  • Do you know that using same `IntVar` on the three checkboxes will check/uncheck the three checkboxes at the same time when any of the checkboxes are checked/unchecked? – acw1668 Sep 20 '21 at 06:46
  • If i give onvalue as 1,2,3 it will check only one at a time. I have checked that one.Everthing works but only scrollbar is not giving its functionality – Piu Sep 20 '21 at 06:50
  • Yes you can do it that way. Then what is your problem if `create_window(...)` are called on each checkbox individually? – acw1668 Sep 20 '21 at 06:55
  • problem on of checkbutton in row are beyond the visible area so i need scrollbar that should scroll – Piu Sep 20 '21 at 07:14
  • Just create a horizontal scrollbar like `scroll_x` in your code, but work on the `ScrolledText` widget instead of `Listbox`. – acw1668 Sep 20 '21 at 07:16
  • I added ScrolledText widget but it is not working , I can see the scrollbar but scrolling functionality is not working . – Piu Sep 20 '21 at 13:29
  • please any suggestion for the same – Piu Sep 20 '21 at 13:53
  • You need to post your updated code, otherwise we can't help. – acw1668 Sep 20 '21 at 15:28

0 Answers0