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

Tim Roberts timr at probo.com
Fri Apr 7 12:35:30 EDT 2017


Kurt Eilander wrote:
> 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 see Eryk provided the explanation, but all I had to do to make your
example work was add
    hDesk.SetThreadDesktop()
just after your SwitchDesktop call.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list