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.
1 Answer
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")
4 Comments
TheBandit
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.
Tom Fuller
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")TheBandit
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)
Tom Fuller
You might find something here: stackoverflow.com/questions/23482748/… The only problem is, you may need to create a separate label for each link.
def print(stuff): <put stuff in GUI>perhaps?Message()function in your question, I think you need to better describe what code you already have written.