-1

How can I print text to my GUI instead of in the console with tkinter? For example if I print "Test" instead of printing Test in my console it should print Test to the next line of the GUI. I need this to work with a large number of printed lines.

TheBandit
  • 109
  • 2
  • 9

1 Answers1

1

NOTE: I'm not sure what you mean by 'print', if this isn't what you're looking for please add a comment

As for 'printing' on your tkinter window, there are a few different ways.

One good way is the label widget, this is a widget which contains text, you can change the font, size, colour and alignment of the text.

mylabel = Label(master, text = "ExampleText", font = ("Purisa", 12)) # master can be a window or a frame
mylabel.pack() # packs the label on to the master

Another method is creating text on a canvas

mycanvas = Canvas(...)
mycanvas.create_text(x = 100, y = 100, text = "ExampleText")
Tom Fuller
  • 5,291
  • 7
  • 33
  • 42
  • I have to make a large number of lines, and the number of lines I will need to print is random. If I use a master to have the position I won't know how many to make, and with the Canvas I also won't know how many to make. – TheBandit Dec 10 '16 at 22:02
  • You can have more than one line in a `Label` and using `create_text`, all you need to do is put a `\n` between each line. For example: `mylabel = Label(master, text = "line1\nline2\nline3")` – Tom Fuller Dec 10 '16 at 22:08
  • Thank you I have it working for the most part besides the positions getting all messed up. Is there a way to make links clickable? (the lines that are printed are all links but it doesn't let me click on them) – TheBandit Dec 10 '16 at 22:18
  • You might find something here: http://stackoverflow.com/questions/23482748/how-to-create-a-hyperlink-with-a-label-in-tkinter The only problem is, you may need to create a separate label for each link. – Tom Fuller Dec 10 '16 at 22:19