Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter ScrolledText

Tags:

python

tkinter

I'm trying to make a Tkinter entry box, but need more space than just one line. It seems that

self.scroll = ScrolledText.ScrolledText(self.tk).pack()

is the best looking way to do it right now, but I dont know how to get the inputted text from self.scroll and use it for something else, theres no clear documentation on it either. Does anyone know?

like image 472
Pascal.S Avatar asked Dec 14 '22 22:12

Pascal.S


1 Answers

Mistake:

self.scroll = ScrolledText.ScrolledText(self.tk).pack()

this way you assign pack() result to self.scroll (not ScrolledText)
and pack() always returns None.

Always:

self.scroll = ScrolledText.ScrolledText(self.tk)
self.scroll.pack()

And now see standard Text Widget documentation how to get/set text.

from tkinter import *
import tkinter.scrolledtext as ScrolledText

master = Tk()

st = ScrolledText.ScrolledText(master)
st.pack()

st.insert(INSERT, "Some text")
st.insert(END, " in ScrolledText")

print(st.get(1.0, END))

master.mainloop()
like image 147
furas Avatar answered Dec 31 '22 06:12

furas