I can't seem to print the contents of the ScrolledText Widget to the console.
I have run the help command on the ScrolledText Widget:
print(help(scrolledtext.ScrolledText))
This outputs that the .get method (used to get the contents of tk.Text Widgets) is present in this widget aswell.
| get(self, index1, index2=None)
| Return the text from INDEX1 to INDEX2 (not included).
So why is it then that the line:
print(myScrollTextWidget.get("1.0","end"))
Results in this error:
AttributeError: 'NoneType' object has no attribute 'get'
When the button is pressed.
Here is a runnable code snippet that I'm working from:
import tkinter as tk
from tkinter import scrolledtext
#Declare Root
root = tk.Tk()
root.title("Scrolltext Widget")
tk.Label(root,text="My Scrolled Text Widget",font=("Times New Roman",25))\
.grid(row=0,column=1)
#Define ScrollTextWidget
#wrap keyword used to wrap around text
myScrollTextWidget = scrolledtext.ScrolledText(root,wrap=tk.WORD,width=50,height=20,font=("Times New Roman",15))\
.grid(row=1,column=1)
print(help(scrolledtext.ScrolledText))
def printToConsole():
print(myScrollTextWidget.get("1.0","end"))
#Buttons
myButton = tk.Button(root,text="Print to console!",command=printToConsole).grid(row=2,column=1)
root.mainloop()