Home > Software design >  Can't scroll to things added to canvas by a button
Can't scroll to things added to canvas by a button

Time:09-15

I'm finishing building an app managing a JSON and while everything is scrolling when it's added before the mainloop starts, if I add it by a button, I can't scroll to the newly added things (I add them by canvas.create_window(0, getfirstfreeposition(), window=thing)). I have the grid weights set up to 1 on my Toplevel and Tk windows and "Configure"=lambda event:canvas.configure(scrollregion=canvas.bbox("all") on all canvases.

Edit: after a bit of research, reopening Toplevel window lest me scroll properly

Edit 2: link to repo with code: https://github.com/Gutek8134/AID-state-creator

CodePudding user response:

You need to reconfigure the scrollregion for the canvas whenever things are added to or removed from the canvas. It can be as simple as doing this after adding one or more items to the canvas:

the_canvas.configure(scrollregion=the_canvas.bbox("all"))
  • Related