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.
Asked
Active
Viewed 2,933 times
-1
-
I'm not sure what to try, the Message() function requires a specific location so I don't think that will work. Is there a function that just prints line by line? – TheBandit Dec 10 '16 at 21:35
-
`def print(stuff):
` perhaps? – Tadhg McDonald-Jensen Dec 10 '16 at 21:53 -
@TheBandit you have not mentioned anything about `Message()` function in your question, I think you need to better describe what code you already have written. – Tadhg McDonald-Jensen Dec 10 '16 at 21:55
1 Answers
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