I have created a scrollbar in Tkinter and it's working fine, but the size of the Scroll Button is not being scaled correctly (normally it's adjusted to the size of the scrollable area).
I'm placing all my widgets with a .pack(), therefore the .grid sticky configuration is something I would like to avoid.
My question is: Which part of the scrollbar configuration is responsible for scaling the height?
The code example:
master = Tk()
FrameBIG = Frame(master)
Main = Canvas(FrameBIG,height = 1200,width =1500,scrollregion=Main.bbox("all"))
scroll = Scrollbar(FrameBIG ,orient="vertical", command=Main.yview)
scroll.pack(side="right", fill="y")
Main.pack(side = BOTTOM, anchor = NW,fill="x")
FrameBIG.pack(anchor = W, fill = "x")
Best Answer
The code
is wrong because
Main
does not exists yet. It should beBut it is meaningless because
Main
canvas was created right now and is empty (so thebbox
method returnsNone
)When you created the scrollbar with
you forgot to complete the two step contract between
scroll
andMain
, so you have to add the line below (just after the creation ofscroll
)Now the code is like this
Now you can notice that the scroll bar does not have the button. Its because the
Main
canvas is empty. Let's add something to theMain
canvasNow the line is there but the scroll button is not there yet, why? Because you have to update the
scrollregion
of theMain
canvas. So let's do it withNow it is working properly. Here the complete code.
In the next question, post a question with a complete working code that shows up you problem. You will get faster and better answers, ok? Have a nice day.