Jorim Straver
Jorim Straver

Reputation: 11

Print information to a text box in Tkinter

I want to make a menu with a message box (or self filling text box) and some buttons.

This message box must contain the printed output from another py program.

Here is my code on Dropbox.

The printed output is in this code: Wunderground_info

Who could help me with this problem?

Upvotes: 0

Views: 1162

Answers (1)

Ellis Michael
Ellis Michael

Reputation: 972

If you really need to get the output from stdout, then you probably need to temporarily redirect it. See: Can I redirect the stdout in python into some sort of string buffer? Then, once you have that output in a string , it should be straightforward to create a frame with it:

from ScrolledText import ScrolledText
import Tkinter as tk

class OutputViewer(tk.Frame):
    def __init__(self, data, master=None):
        tk.Frame.__init__(self, master)
        self.text = ScrolledText(self, width=90, height=13)
        self.text.pack()
        self.text.insert(tk.END, data)
        self.text.see(tk.END)

Hope that helps.

Upvotes: 3

Related Questions