Advertisements
so I tried inserting a scrollbar into my Window with this code:
scrollbar= Scrollbar(root)#root is my window
list = [1,2,3,4,5]
for element in list:
scrollbar.insert(END, element)
scrollbar.pack(side="left")
but the attribute I’m trying to use somehow doesn’t work…
I got this error:
AttributeError: 'Scrollbar' object has no attribute 'insert'
Could someone please help me I don’t
>Solution :
It looks actually, ‘Scrollbar’ object actually does not have attribute ‘insert’ , I think you were trying to use ‘Listbox’ object which also is used to make a scrollbar (to make it functional) , because it has ‘insert’ attribute (I mean ‘Listbox’)
So this is a sample code for a scrollbar and how to use it! Even make it functional and useable! 🙂
from tkinter import *
root = Tk()
root.geometry("150x200")
w = Label(root, text ='My Scrollbar',
font = "50")
w.pack()
scroll_bar = Scrollbar(root)
scroll_bar.pack( side = RIGHT,
fill = Y )
mylist = Listbox(root,
yscrollcommand = scroll_bar.set )
for line in range(1, 26):
mylist.insert(END, "Item Num#" + str(line))
mylist.pack( side = LEFT, fill = BOTH )
scroll_bar.config( command = mylist.yview )
root.mainloop()
For more check this! Python-Tkinter Scrollbar – GeeksforGeeks
Tell me if it works!