Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'Scrollbar' object has no attribute 'insert'

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'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading