Python Forum
[Tkinter] Updating Tkinter label using multiprocessing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Updating Tkinter label using multiprocessing
#1
Hi!
I'm having trouble updating a label depending on a result from a function from one of the two processes I'm running. I'm trying using Queues, but can't make it work.

This is a simplified example of the code:

import multiprocessing as mp
from tkinter import DISABLED, NORMAL, Label, LabelFrame, Tk
import queue

class Gui(object):
    def __init__(self, q):
        self.root = Tk()
        self.root.geometry('150x100')

        self.frameP1 = LabelFrame(self.root, text="Process1", font=("Helvetica", 14, "bold"), bd=0)
        self.frameP1.pack(padx=12)
        self.currentUserProcess1 = Label(self.frameP1, text="Current User p1", font=("Helvetica", 10, "bold"))
        self.currentUserProcess1.pack()
        
        self.frameP2 = LabelFrame(self.root, text="Process2", font=("Helvetica", 14, "bold"), bd=0)
        self.frameP2.pack()
        self.currentUserProcess2 = Label(self.frameP2, text="Current User p2", font=("Helvetica", 10, "bold"))
        self.currentUserProcess2.pack()
        self.root.after(100,self.CheckQueuePoll,q)
    

    def CheckQueuePoll(self, c_queue):
        try:
            str = c_queue(0)
            self.currentUserProcess2.configure(text=str)
        except queue.Empty:
            pass
        finally:
            self.root.after(100, self.CheckQueuePoll, q)

def process1():
    print("Executing process1")
    
    #doSomething

def process2():
    print("Executing process2")
    log = "Current User Process 2"
    q.put(log)

def startProcesses():
    global p1
    global p2
    p1 = mp.Process(target = process1)
    p2 = mp.Process(target = process2)
    p1.start()
    p2.start()


def stopProcesses():
    p1.terminate()
    p2.terminate()
       
if __name__ == '__main__':
    q = mp.Queue()
    gui = Gui(q)
    p1 = mp.Process(target = process1, args=(q,))
    p2 = mp.Process(target = process2, args=(q,))
    p1.start()
    p2.start()
    gui.root.mainloop()
This is giving me this error:
Error:
TypeError: 'Queue' object is not callable
This happens when trying to execute "str = c_queue(0)" on CheckQueuePoll function.
I tried different ways of importing Queue, but I always get errors. I'd appreciate any help or hint in what I'm doing wrong.
Thanks in advance!
Reply


Messages In This Thread
Updating Tkinter label using multiprocessing - by Agusms - Aug-12-2022, 02:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 907 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,670 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
  [Tkinter] Updating tkinter text BliepMonster 5 6,411 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,237 Jun-26-2022, 06:26 PM
Last Post: menator01
  [Tkinter] Making entry global in tkinter with multiprocessing luckyingermany 2 2,379 Jan-21-2022, 03:46 PM
Last Post: deanhystad
  tkinter: Image to Label Maryan 10 5,454 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Tkinter - How can I extend a label widget? TurboC 2 2,875 Oct-13-2020, 12:15 PM
Last Post: zazas321
  Tkinter: How to assign calculated value to a Label LoneStar 7 4,013 Sep-03-2020, 08:19 PM
Last Post: LoneStar
  [Tkinter] updating tkinter chart from within function mikisDW 1 1,982 Jul-02-2020, 03:33 AM
Last Post: deanhystad
  changing tkinter label from thread nanok66 3 7,536 Jun-07-2020, 01:37 AM
Last Post: nanok66

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020