0
I have a screen class, which contains a label of text, the code loads an xml containing the objects.
py screen.:
#!/usr/bin/python3
import gi
import modulo_arquivos
import os
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
# diretorios dos arquivos
diretorio_exe = os.path.dirname(os.path.realpath(__file__))
diretorio_proj = diretorio_exe + '/'
diretorio_tela = diretorio_proj + 'screens/tela_principal/tela_principal.glade'
class tela_principal():
def carrega_arquivo_xml(self):
self.tela_builder = Gtk.Builder()
self.tela_builder.add_from_file(diretorio_tela)
self.janela = self.tela_builder.get_object("Janela")
self.label_txt = self.tela_builder.get_object('txt_ps_atual01')
def abre_tela(self):
self.janela.show()
def fecha_tela(self):
self.janela.hide()
def escreve_txt(self, texto):
self.label_txt.set_text(texto))
And I have a main file that creates the screen instance and has it open. In the main code I have two processes according to the code below:
#!/usr/bin/python3
#IMPORTS
import gi
gi.require_version("Gtk", "3.0")
from multiprocessing import Process, Queue, Pipe
from gi.repository import Gtk, GObject
import tela
tela_principal = tela.tela_principal()
tela_principal.carrega_arquivo_xml()
tela_principal.abre_tela()
def escreve_texto(texto):
tela_principal.escreve_txt(texto)
def interface_grafica(tx, rx):
while True:
Gtk.main_iteration_do(False)
#escreve_texto('HELLO')
def comunicacao_serial(tx,rx):
escreve_texto('HELLO2')
if __name__ == "__main__":
queue1 = Queue()
queue2 = Queue()
p1 = Process(target=interface_grafica, args=(queue1, queue2,))
p2 = Process(target=comunicacao_serial, args=(queue2, queue1,))
p1.start()
p2.start()
p1.join()
p2.join()
The problem is that the label is only modified within the graphical interface function, but within the communication function it is not changed. Why this happens and how to solve?
Thank you for that enlightening reply!
– HelloWorld