I'm a little stuck here. I've read lots of stack overflows threads but not getting any further on that topic.
My goal is to have a tinter GUI that at some point launches a function in a new Process and redirects every print in that function to the Guis Text widget. There a Pipes and Queues but im not to familiar with how to use them correctly. I have found a working solution here but that only applies to Python 3. Unfortunately I have to use Python 2.7...
Can anybody help?
my sample code:
from Tkinter import *
import multiprocessing as mp
import time
import sys
class Gui(object):
def __init__(self):
self.a=Tk()
b1=Button(self.a, text="Process 1", command=self.func)
b1.grid(row=0, column=0, pady=10, padx=10, sticky=SE)
self.messages=Text(
self.a, height=2.5, width=30, bg="light cyan", state=NORMAL)
self.messages.grid(row=1, column=0, columnspan=3)
sys.stdout = self.StdoutRedirector(self.messages)
sys.stderr = self.StdoutRedirector(self.messages)
self.a.mainloop()
class StdoutRedirector(object):
def __init__(self, text_widget):
self.output = text_widget
def write(self, string):
self.output.config(state=NORMAL)
self.output.update_idletasks()
self.output.insert('end', string)
self.output.see('end')
self.output.config(state=DISABLED)
def flush(self):
pass
def func(self):
print("test")
proc=mp.Process(target=go)
proc.start()
def go():
for i in range(0,10):
time.sleep((1))
print(i)
if __name__ == "__main__":
Gui()