0

I have created tkinter window and created a frame and in that frame, I have created a canvas and also linked scrollbar to it. In canvas I have created 3 labels one below other.
Now, when I try to scroll, the slider just moves and the label doesn't move.
Why is this happening? I am a new to python and tkinter can you guys please tell where am I going wrong or am I missing some code?

enter image description here

Here you can see that I am trying to scroll but only the slider is moving but not the label, that is, the content inside it.

So this is my code:

def news_frame():

    my_frame=Frame(mw)
    my_frame.pack()
   
    my_scrollbar=Scrollbar(my_frame,orient=VERTICAL)
    my_scrollbar.pack(side=RIGHT,fill=Y)

    my_canvas=Canvas(my_frame,width=1980,height=1200,scrollregion= 
    (0,0,2000,1500),yscrollcommand=my_scrollbar.set)
    my_canvas.pack()

    label1=Label(my_canvas,text=title)
    label1.place(x=500,y=20)
    my_scrollbar.config(command=my_canvas.yview)

    newslblframe=Label(my_canvas,bg="white",bd=5,relief=RAISED)
    newslblframe.place(x=20,y=45,width=1320,height=245)

    newslblframe2=Label(my_canvas,bg="white",text=title,bd=5,relief=RAISED)
    newslblframe2.place(x=20,y=300,width=1320,height=245)

    newslblframe2=Label(my_canvas,bg="white",text=title,bd=5,relief=RAISED)
    newslblframe2.place(x=20,y=553,width=1320,height=245)
CoolCoder
  • 786
  • 7
  • 20
  • 1
    Does this answer your question? [Adding a scrollbar to a group of widgets in Tkinter](https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter) – Thingamabobs Jun 05 '21 at 08:38
  • 1
    You cant use scrollbar with `place`. Instead use `.pack()` and set the master of your labels to a frame that you then use in the canvas via *create_window*. Then bind a configure event to the frame so your scrollbar updatest and the scrollregion of canvas. See the link I have posted. – Thingamabobs Jun 05 '21 at 08:43
  • @Atlas435 I'm getting bit confused here can you please show me using my code please so that it gets clarified – Anime Nerdy Jun 05 '21 at 09:04
  • You can use `my_canvas.create_text(...)` instead of using labels if you just want to show some text inside the canvas. – acw1668 Jun 05 '21 at 14:32
  • @acw1668 I wanna show images as well along with text – Anime Nerdy Jun 05 '21 at 15:23
  • Then use `my_canvas.create_window()` to put those labels inside `my_canvas` instead of using `.place()`. – acw1668 Jun 06 '21 at 10:29

0 Answers0