0

I am trying to create four frames, canvas and scrollbar with for loop. The code works and i can access each frame from out the loop and insert the labels that I need. The problem is that the scrollbar can be moved only on the last frame.

f_s = ['s_one', 's_two', 's_three', 's_four']
f_o = ['f_one', 'f_two', 'f_three', 'f_four']
f_c = ['c_one', 'c_two', 'c_three', 'c_four']
f_f = ['fs_one', 'fs_two', 'fs_three', 'fs_four']
for f in range(4):
    f_o[f] = Frame(self.f_bot, width=250, height=600, bg=self.bg)
    f_o[f].grid(row=1, column=f)
    f_o[f].grid_propagate(False)
    f_c[f] = Canvas(f_o[f], width=width_s, height=600, bg=self.bg)
    f_c[f].pack(side=LEFT, fill=BOTH, expand=1)
    f_s[f] = Scrollbar(f_o[f], orient=VERTICAL, command=f_c[f].yview, bg=self.bg)
    f_s[f].pack(side=RIGHT, fill=Y)
    f_c[f].configure(yscrollcommand=f_s[f].set)
    f_c[f].bind('<Configure>', lambda event: f_c[f].configure(scrollregion=f_c[f].bbox('all')))
    f_f[f] = Frame(f_c[t], bg=self.bg)
    f_c[f].create_window((0, 0), window=f_f[f], anchor='nw')

If I change the value here:

f_c[f].bind('<Configure>', lambda event: **f_c[f-1]**.configure(scrollregion=f_c[f].bbox('all')))

the scroll will move to the previous frame.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • What do you mean by *"the scroll will move to the previous frame"*? BTW it is the same issue of your previous deleted question: `f_c[f]` in the event callback always refer to the last canvas. So `f_c[f-1]` will refer to the second last canvas. For your case, change `f_c[f]` to `event.widget` inside the lambda. Also as said in my comment in your deleted question, event `` should be bound on the inner frame instead of the canvas. – acw1668 Aug 14 '22 at 14:54
  • Thanks a lot man, and sorry for deleting the first post but it was the first one and i though i didnt explain it very well. this worked # f_c[f].bind('', lambda event: event.widget.configure(scrollregion=event.widget.bbox('all'))) – Edmond Cepele Aug 14 '22 at 15:11
  • Please don't abuse blockquotes (`>`) for emphasis. They should only be used for quotes. – ChrisGPT was on strike Aug 14 '22 at 23:09

0 Answers0