-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.

3
  • 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? Commented Dec 10, 2016 at 21:35
  • def print(stuff): <put stuff in GUI> perhaps? Commented Dec 10, 2016 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. Commented Dec 10, 2016 at 21:55

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

4 Comments

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.
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")
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)
You might find something here: stackoverflow.com/questions/23482748/… The only problem is, you may need to create a separate label for each link.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.