I'd like to create a simple, reusable text output window class in Python / Tkinter that functions just like the console output, but with a nicer window.
So far I managed to write text into a ScrolledText
widget directly from within the constructor, but that is not what I want.
I'd like to create a print
or println
method that lets me add text from the main procedure any time.
How can I 'call' the text widget from within the print method?
My main procedure:
from gui.simpleio import Textwindow
a = Textwindow("This is my Textwindow !")
a.print("I'd like to see a hello from the print method")
a.stxt.INSERT("but nothing happens")
My Textwindow class in the gui package (simpleio.py):
from tkinter import Tk, Frame, INSERT
from tkinter import scrolledtext
class Textwindow(Frame):
def __init__(self , title):
root = Tk()
stxt = scrolledtext.ScrolledText(root)
stxt.pack()
root.wm_title(title)
stxt.insert(INSERT,"blah\nblabla\n")
stxt.insert(INSERT,"yes\nno")
root.mainloop()
def print(self,text):
#self.stxt.insert(INSERT,text)
pass