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)
>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)