Forum: Poser Python Scripting


Subject: running two scripts (with tkinter GUI) at the same time

tromnek opened this issue on Dec 04, 2004 ยท 10 posts


PoseWorks posted Tue, 07 December 2004 at 12:17 AM

You could try setting a callback with after_idle([,args]) that would set WM_DELETE_WINDOW to a function of your choosing (one that didn't delete windows at all) after the alien script had gone to the mainloop. An example would be: ------------------- > def nullify(): > -----pass > def reset_x(master): #may need an event arg too, not sure > -----master.protocol('WM_DELETE_WINDOW',nullify) > master.after_idle(reset_x, master) > exec("script.py") ------------------- This has the unhappy side-effect of making the user unable to destroy windows through the system's close button though. If you know that the script that you want to execute is safe, you could do something like this: ------------------- file = open("script.py",'r') file_data = file.read() file.close() import re new_data = re.compile("""Tk()""").sub("Toplevel()",file_data) file = open("temp_script.py",'w') file.write(new_data) file.close() exec("temp_script.py") ------------------- But it's somewhat dangerous to monkey with someone else's code. What's the reason for trying to execute someone else's script, and would be consistently be the same script?