Mar-31-2018, 01:22 PM
(This post was last modified: Mar-31-2018, 01:22 PM by Gribouillis.)
The child process cannot find
do_solve
, probably because the if __name__ == '__main__'
part is not executed in the child process. Try to refactor the code this way# tksudo.py import solvesudo def do_solve(sudoku): status = solvesudo.wsolve(sudoku) return status, sudoku if __name__ == '__main__': from tkinter import Tk, Frame, Entry, Label, Button, IntVar, StringVar, LEFT from tkinter import messagebox from tkcallasync import tk_call_async, MULTIPROCESSING disabled = False def execute_solver(): global disabled if disabled: messagebox.showinfo("warning", "It's still calculating...") return def callback(result): global disabled disabled = False status, sudoku = result solvesudo.printSUDOKU(sudoku) result_var.set('Found!' if status else 'Not Found!') disabled = True tk_call_async(root, do_solve, args=(solvesudo.sudoku,), callback=callback, method=MULTIPROCESSING) root = Tk() row = Frame(root) row.pack() Button(row, text="Solve Sudoku", command =execute_solver).pack(side=LEFT) Button(row, text="It's responsive", command= lambda: messagebox.showinfo("info", "it's responsive")).pack(side=LEFT) result_var = StringVar() Label(root, textvariable=result_var).pack() root.mainloop()