Xamber Xamber - 1 month ago 9
Python Question

Easier way to display text in python3

I've been trying past 12h display text in python 3 with tkinter, seemed easy but this is what I've come up with. (Just recently started with python) But there has to be an easier way to display a window and some text inside of it?

from tkinter import *

class Window(Frame):

def __init__(self, master = None):
Frame.__init__(self, master)

self.master = master

self.init_window()

def init_window(self):
self.master.title("GUI")
self.pack(fill=BOTH, expand=1, command=self.showTxt())


def showTxt(self):
text = Label(self, text='Hello world...')
text.pack()


root = Tk()
root.geometry("400x300")
app = Window(root)

root.mainloop()

Answer

Try this :

from Tkinter import *
root = Tk()
T = Text(root, height=2, width=30)
T.pack()
T.insert(END, "Just a text Widget\nin two lines\n")
mainloop()