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

Adding Scrollbar to Tkinter Textbox Giving Unknown Error?

I was adding a scrollbar to my tkinter project (a text editor) but when I tested it after I added the scrollbar it gave me this error:

  File "C:\Users\Diana\Desktop\python\test.py", line 9, in <module>
    scroll_y.config(command=text.yview)
AttributeError: 'NoneType' object has no attribute 'yview'

Here is my code for adding the scrollbar to the text widget:

scroll_y = Scrollbar(root)
scroll_y.pack(side = RIGHT, fill = Y)
text = Text(root, height=40,width=15, yscrollcommand=scroll_y.set).pack(side=RIGHT)
scroll_y.config(command=text.yview)

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

>Solution :

The grid, pack, and place methods of every Tkinter widget work in-place (they always return None). Meaning, you need to call them on their own lines:

Instead of Using in one line:

text = Text(root, height=40,width=15, yscrollcommand=scroll_y.set).pack(side=RIGHT)

You have to use:

text = Text(root, height=40,width=15, yscrollcommand=scroll_y.set)
text.pack(side=RIGHT)
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