[python-win32] CreateDesktop() and displaying a window on it

Kurt Eilander webguy at totalrewind.com
Thu Apr 6 15:38:45 EDT 2017


Hey all,

I'm trying to get system modal functionality like the UAC dialog.

According to http://developex.com/blog/system-modal-back/ the thing to 
do is to create and switch to a new desktop.

Therefore, I'm doing:

hDeskOld=win32service.GetThreadDesktop(win32api.GetCurrentThreadId())
hDesk=win32service.CreateDesktop("SysModalDesktop",0,win32con.GENERIC_ALL,None) 

     hDesk.SwitchDesktop() # switch to the new desktop
     try:
         root=Tk()
         app=SysmodalDialog(root,title,message,img)
         app.mainloop()
     except Exception,e:
         print e
     hDeskOld.SwitchDesktop() # switch back
     hDesk.CloseDesktop() # done

The tk stuff inside the try works fine on its own.
If I replace the Tk stuff with time.sleep(5.0), then desktops switch 
fine as well.

The problem is I can't get the tk app to show on the new desktop (and 
therefore mainloop() blocks and I can't get back out of it!)

I tried changing Tk() to Tk(screenName="SysModalDesktop") but that 
didn't make a difference.

How do I make my window go to the right desktop??

-Kurt



More information about the python-win32 mailing list