[Tkinter-discuss] Keeping keyboard focus when window iconified (Win XP) ?

francois schnell francois.schnell at gmail.com
Tue Jan 10 18:17:21 CET 2006


Thanks very much Gill for the UI update help.

I've also found something very interesting to control the app when it's not
in focus anymore with pyHook:

The pyHook library wraps the low-level mouse and keyboard hooks in the
Windows Hooking API for use in Python applications. This short tutorial
demonstrates how to set keyboard and mouse hooks, what information is
available about events, and how to pass or block events.

http://www.cs.unc.edu/~parente/tech/tr08.shtml

Python rocks :)
cheers

francois



On 10/01/06, Amanjit Gill <amanjit.gill at gmx.de> wrote:
>
> Hi there
>
> ui updates with tkinter will only happen IMHO after your method returns.
> use the widget.after() method (check
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html)
> <http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html%29>.
> Something
> like this:
>
> def screenshot(event):
>     fen1.iconify()
>     fen1.after(200,doscreen)
>
> i=0
> def doscreen():
>     global i
>     print " screen !"
>     i= i+1
>     name = "session1picture"
>     name= name + str(i)
>     print name
>     myscreen= ImageGrab.grab()
>     myscreen.show()
>     myscreen.save("C:/"+name+ '.jpeg')
>     fen1.deiconify()
>
> If you want ro remove the taskbar entry you can apply the win32 style
> MYWS_EX_NOACTIVATE (at least with win2000 or later). This requires C
> programming, and is just the first thing that came into my mind.
>
> cheers
> Amanjit Singh Gill
>
> >Hello,
> >
> >I'm doing a small program to capture screenshots.
> >
> >But obviously I don't wan my GUI to be visible during the sreenshots and
> I
> >want to continue to take sreenshots (with my key binding) even when the
> >program doesn't have the main focus anymore.
> >
> >I'm running Python 2.4 on Win XP Family.
> >
> >Do you have an idea how I could do this ?
> >
> >Thanks in advance
> >
> >francois
> >
> >---
> >import sys, os, msvcrt, Image, ImageGrab
> >from Tkinter import *
> >from os import chdir
> >
> >def exitapp():
> >    fen1.quit()
> >    fen1.destroy()
> >
> >i=0
> >def screenshot(event):
> >    fen1.iconify()
> >    global i
> >    print " screen !"
> >    i= i+1
> >    name = "session1picture"
> >    name= name + str(i)
> >    print name
> >    myscreen= ImageGrab.grab()
> >    myscreen.show()
> >    myscreen.save("C:/"+name+ '.jpeg')
> >    fen1.deiconify()
> >
> >def invisible():
> >    fen1.iconify()
> >
> >#GUI launch
> >fen1=Tk()
> >fen1.title("Screenshots Tests")
> >bu11=Button(fen1, text='screenshot')
> >fen1.bind("s",screenshot)
> >#fen1.bind_all("s",screenshot)
> >bu11.bind("<Button-1>",screenshot)
> >buQuit=Button(fen1, width= 20, text='Quitter',command=exitapp)
> >bu12=Button(fen1, text='invisible', command=invisible)
> >
> >bu11.pack()
> >bu12.pack()
> >buQuit.pack()
> >
> >fen1.mainloop()
> >
> >
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >Tkinter-discuss mailing list
> >Tkinter-discuss at python.org
> > http://mail.python.org/mailman/listinfo/tkinter-discuss
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060110/1b09a5e9/attachment.htm 


More information about the Tkinter-discuss mailing list