1
import Tkinter,multiprocessing

class cambiar(object):
    def __init__(self,master,estado=False):
        self.master = master
        if estado == False:
            self.run()

    def run(self):
        self.master['text'] = 'que tal'

class body(object):
    def __init__(self,win):
        self.win = win
        lista = ['label','botones']
        cont = len(lista)
        for i in range(cont):
            eval('self.'+str(lista[i]+'()'))

    def label(self):
        self.label_1 = Tkinter.Label(self.win,text='hola')
        self.label_1.grid(row=0,column=0)

    def botones(self):
        self.boton_1 = Tkinter.Button(self.win,text='cambiar',command=lambda :self.win.proceso(self.label_1))
        self.boton_1.grid(row=1,column=0)


class main(Tkinter.Tk):
    def __init__(self):
        Tkinter.Tk.__init__(self)
        self.geometry('500x500')
        self.b = body(self)

    def proceso(self,wid):
        self.p = multiprocessing.Process(target=cambiar,args=(wid,))
        self.p.start()

root = main()
root.mainloop()

I have this code, which oddly makes no sense what I want is to learn the main process can change properties, such as a label in this case, does anyone know how can I do that?

user3509050
  • 31
  • 2
  • 4

1 Answers1

-1
  1. If this is your code I do not know why you use multiprocessing instead of threading.
  2. Use multiprocessing.Pool and wait until a future of an asynchronous call is ready. You can wait by sheduling a function with root.after which tests the future state. Change the label when the parallel computation is done = Change the label when the future has a value.
User
  • 14,131
  • 2
  • 40
  • 59
  • only use multiprocessing for example, the actual code is for Kivy but I'm testing with tkinter and Kivy asks me to use multiprocessing for a program, is there any way to do what I want with multiprocessing? – user3509050 May 02 '14 at 20:01
  • Yes there are ways but they are not so nice since you can not reference a created object. http://stackoverflow.com/questions/21968278/multiprocessing-share-unserializable-objects-between-processes Try out number 2. You should not change the label from another process but from the mainloop-thread. – User May 02 '14 at 20:03
  • Have a look at the side-bar. There are useful links. This is one of them: http://stackoverflow.com/questions/15057789/multiprocessing-in-python-tkinter?rq=1 – User May 05 '14 at 10:50
  • thanks for the replies. Kivy but tells me to have to use multiprocessing socket, the code is extensive so just put an example, I think the solution is to create a thread to the main thread, create a process for socket and change information with Queue. – user3509050 May 05 '14 at 13:24