Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to redirect stdout to a Tkinter Text widget
    primarykey
    data
    text
    <p>My base program imports it's GUI interface from a script GUI.py</p> <pre><code>old_stdout = sys.stdout root = Tk.Tk() root.title('Coursera-dl') root.geometry("345x230") app = GUI.Interface(root) app.mainloop() if app.button_press() == True and app.return_data(): data = app.return_data() main(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8]) sys.stdout = old_stdout </code></pre> <p>In my GUI.py :</p> <pre><code>class Interface(ttk.Frame): def __init__(self,parent=None): ttk.Frame.__init__(self,parent) self.parent = parent self.New_Window() def New_Window(self): self.newWindow = Tk.Toplevel(self.parent) self.app = CoreGUI(self.newWindow) class StdoutRedirector(object): def __init__(self,text_widget): self.text_space = text_widget def write(self,string): self.text_space.insert('end', string) self.text_space.see('end') class CoreGUI(object): def __init__(self,parent): self.parent = parent self.InitUI() def InitUI(self): self.text_box = Tk.Text(self.parent, wrap='word', height = 11, width=50) self.text_box.grid(column=0, row=0, columnspan = 2, sticky='NSWE', padx=5, pady=5) sys.stdout = StdoutRedirector(self.text_box) </code></pre> <p>But what It does is it opens two windows and the first window <em>(the toplevel one)</em> works as expected and the second is <strong>idle</strong> , <em>This is what is expected until I click a certain button</em> which after pressing prints data continuously and the data printed should appear in the second window's text widget <strong>however</strong> this doesn't happen and there is no response from the program and when I close the Toplevel window an error message appears</p> <blockquote> <p>"TclError: invalid command name "".33328904.33329104"""</p> </blockquote> <p>So How can I print the data in Text Widget rather than in the console?</p> <hr> <h1>EDIT:</h1> <p>Inorder to help ya'll if you struggling with this, I've made a script to redirect stdout to a Tkinter Text widget, see it in action <a href="https://gist.github.com/K-DawG007/7729555" rel="nofollow">here</a> :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload