[Tkinter-discuss] how to display terminal messages in a dialog boxusing tkinter

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Mon Feb 25 13:56:00 CET 2008


Gigs_ wrote:
> brindly sujith wrote:
>> hi
>>  
>> i m developing a application using tkinter
>>  
>> i want the messages that we get in the terminal to be displayed in the 
>> tkinter dialog box
>>  
>> do we have any option for that
>>  
>> thank you
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
>> http://mail.python.org/mailman/listinfo/tkinter-discuss
>>   
> maybe you could redirect sys.stdout to tkinter textbox. or make wrapper 
> for stdout
> 
> or something like this
> 
> class Klass():
>     def __init__(self):
>         self.x = ''
>     def write(self, c):
>         self.x += c
>     def writelines(self, l):
>         for i in l:
>             self.x += i
> w = Wrapper()
>  sys.stdout = w
> 
> and insert w.x to tkinter text
> t.insert(1.1, w.x)
> w.x = ''
> 
> dont know much about tkinter, but i hope that this help you
> 
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
> 


Extending the Tkinter.Text widget works great here, give it a write 
method and optionally scroll to the inserted text too...


class STDText(Text):
   def __init__(self, parent):
     Text.__init__(self, parent)

   def write(self, stuff):
     self.insert("end", stuff)
     self.yview_pickplace("end")

root=Tk()
sText = STDText(root)
sText.pack()

sys.stdout = sText


root.mainloop()









-- 
signature file not found, must be something I ate


More information about the Tkinter-discuss mailing list