0

I wanted to create scrollbar on frame for this i used canvas. After creating canvas i created scrollbar on root and connect it to canvas. then i try to create entry box but my entry box is overlapping scrollbar which i don't want. why entry box is overlapping and how can it correct it. also scrollbar does not stick to right does i have to bind canvas to root window to resize it.

here is my code

from tkinter import *
from tkinter import ttk
from youtubesearchpython import VideosSearch
root = Tk()
root.title("Sasta YuTube")
root.geometry("600x600")
class top_level:
    def __init__(self,root):
        self.root = root

        self.yscroll = ttk.Scrollbar(self.root,orient = VERTICAL)
        self.yscroll.grid(row = 0, column = 1,sticky = "nse")
        
        self.my_canvas = Canvas(self.root,yscrollcommand=self.yscroll.set,width = 580,height = 600)
        self.my_canvas.grid(row = 0,column = 0,sticky = "nsew")
        
        self.yscroll.config(command = self.my_canvas.yview)
        
        self.entrybox_frame = Frame(root)
        self.entry_frame_id = self.my_canvas.create_window(0,0,window = self.entrybox_frame,anchor = "nw")
        self.search_btn = ttk.Button(self.entrybox_frame,text = "search")
        self.search_btn.pack(side = "bottom",anchor = "w")
        self.entry_box = Entry(self.entrybox_frame,width = 550)
        self.entry_box.pack(side = "top")
        
root.mainloop()
obj = top_level(root)

1 Answers1

0

Tkinter uses the parent/child relationship of widgets to know how to render the widgets on the screen. Because the frame is a direct child of the root window, it is only constrained by the root window and not the canvas.

If you want it to be constrained to the edges of the canvas it needs to be a child of the canvas.

self.entrybox_frame = Frame(self.my_canvas)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Can we close this question as a duplicate of [this](https://stackoverflow.com/q/68808595/11106801)? Also this is the 3rd question like this in the past week... – TheLizzard Aug 23 '21 at 15:54