Search code examples
pythonpython-3.xtkinterobfuscationpyarmor

pyarmor shows tkinter window multiple times


below tool.py code script, while running that code using cmd
tool.py command, it runs successfully 100%
when I try to pack the code using pyarmor by below command in cmd
pyarmor pack -e "--onefile " tool.py
and then I run exe file, it shows win00 window when I press submit button, first it starts to run code.
but at the middle of running it, it shows tkinter win00 window again, which stops the first code running
Func00 and Func01 include multiprocessing processes, each Func includes 5 processes.
tool.py

import tkinter as tk
from deployedFunc00 import *
from deployedFunc01 import *

def button_fn():
    if clicked.get() == 'func00':
        if __name__ == '__main__':
            Func00()
    else:
        if __name__ == '__main__':
            Func01()
            
def show():
    label_.config(text=clicked.get())
    
if __name__ == '__main__':
    win00 = tk.Tk()
    win00.geometry("300x300")
    win00.eval('tk::PlaceWindow . center')

    frame00 = tk.Frame(win00)
    frame00.pack_propagate(0)
    frame00.pack(fill=tk.BOTH, expand=1)

    options = ['func00','func01']
    clicked = tk.StringVar()
    clicked.set('func00')

    drop = tk.OptionMenu(frame00, clicked, *options)
    drop.pack()
    
    label_ = tk.Label(frame00, text=" ")
    label_.pack()
    
    button0 = tk.Button(frame00,text="choose",command=show).pack()

    button1 = tk.Button(frame00,text='submit',command= button_fn)
    button1.pack(side=tk.BOTTOM,pady=(0,10))

    win00.mainloop()

deployedFunc00.py

import multiprocessing
from func05 import *


def Func00():
    LENGTH = 5


    jobs = []         
    for n in range(LENGTH):
        globals()['p_%s' %n] = multiprocessing.Process(target = Func05)
        
    for n in range(LENGTH):
        jobs.append(globals()['p_%s' %n])
        
    for n in range(LENGTH):
        globals()['p_%s' %n].start()
        
    for proc in jobs:
        proc.join()

deployedFunc01.py

import multiprocessing

from func06 import *

def Func01():
    LENGTH = 5


    jobs = []         
    for n in range(LENGTH):
        globals()['p_%s' %n] = multiprocessing.Process(target = Func06)
        
    for n in range(LENGTH):
        jobs.append(globals()['p_%s' %n])
        
    for n in range(LENGTH):
        globals()['p_%s' %n].start()
        
    for proc in jobs:
        proc.join()

Solution

  • Finally I found a solution: just put

    multiprocessing.freeze_support()
    

    after

    if __name__ == '__main__':
    

    reference: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing