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
#5
(Aug-12-2022, 07:04 PM)woooee Wrote: Pass gui.currentUserProcess 1 or 2 to the process as an arg. Each process can then update it.

I tried it. This is the code I got, in case I did something wrong:
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()

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

def process2(currentUserProcess2):
    print("Executing process2")
    log = "Current user process 2"
    currentUserProcess2.configure(text=log)

def startProcesses():
    global p1
    global p2
    p1 = mp.Process(target = process1, args=(gui.currentUserProcess2,))
    p2 = mp.Process(target = process2, args=(gui.currentUserProcess2,))
    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=(gui.currentUserProcess2,))
    p2 = mp.Process(target = process2, args=(gui.currentUserProcess2,))
    p1.start()
    p2.start()
    gui.root.mainloop()
I got this:

Error:
Traceback (most recent call last): File "c:\Users\User1\Desktop\MultiTkinter\main.py", line 63, in <module> p1.start() File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 121, in start self._popen = self._Popen(self) File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 224, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 327, in _Popen return Popen(process_obj) File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__ reduction.dump(process_obj, to_child) File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) TypeError: cannot pickle '_tkinter.tkapp' object PS C:\Users\User1\Desktop\MultiTkinter> Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 107, in spawn_main new_handle = reduction.duplicate(pipe_handle, File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\reduction.py", line 79, in duplicate return _winapi.DuplicateHandle( PermissionError: [WinError 5] Access is denied
I deleted CheckQueuePoll function as I understand it wouldn't be needed if I'm passing "gui.CurrenUserProcess2" in the parameters.
Reply


Messages In This Thread
RE: Updating Tkinter label using multiprocessing - by Agusms - Aug-12-2022, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 957 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,699 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
  [Tkinter] Updating tkinter text BliepMonster 5 6,510 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,318 Jun-26-2022, 06:26 PM
Last Post: menator01
  [Tkinter] Making entry global in tkinter with multiprocessing luckyingermany 2 2,396 Jan-21-2022, 03:46 PM
Last Post: deanhystad
  tkinter: Image to Label Maryan 10 5,477 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Tkinter - How can I extend a label widget? TurboC 2 2,887 Oct-13-2020, 12:15 PM
Last Post: zazas321
  Tkinter: How to assign calculated value to a Label LoneStar 7 4,050 Sep-03-2020, 08:19 PM
Last Post: LoneStar
  [Tkinter] updating tkinter chart from within function mikisDW 1 1,996 Jul-02-2020, 03:33 AM
Last Post: deanhystad
  changing tkinter label from thread nanok66 3 7,585 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