Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99133
| From | eryksun <eryksun@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: non-blocking getkey? |
| Date | 2015-11-20 02:43 -0600 |
| Message-ID | <mailman.509.1448009036.16136.python-list@python.org> (permalink) |
| References | (3 earlier) <n2hlr7$d1j$2@news2.informatik.uni-stuttgart.de> <n2ia83$icf$2@news2.informatik.uni-stuttgart.de> <mailman.419.1447869376.16136.python-list@python.org> <n2kqvn$8de$1@news2.informatik.uni-stuttgart.de> <564DF94E.8020302@gmail.com> |
On Thu, Nov 19, 2015 at 10:31 AM, Michael Torrie <torriem@gmail.com> wrote:
> One windows it might be possible to use the win32 api to enumerate the
> windows, find your console window and switch to it.
You can call GetConsoleWindow [1] and then SetForegroundWindow [2].
import os
import sys
try:
import tkinter
from tkinter import filedialog
except ImportError:
import Tkinter as tkinter
import tkFileDialog as filedialog
input = raw_input
if sys.platform == 'win32':
import ctypes
kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')
def setfgwin():
hcon = kernel32.GetConsoleWindow()
if hcon and user32.SetForegroundWindow(hcon):
return True
return False
def get_filename():
filename = filedialog.askopenfilename()
setfgwin()
return os.path.normpath(filename)
if __name__ == '__main__':
root = tkinter.Tk()
root.withdraw()
filename = get_filename()
print('filename: %s' % filename)
input('press enter...')
[1]: https://msdn.microsoft.com/en-us/library/ms683175
[2]: https://msdn.microsoft.com/en-us/library/ms633539
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 08:39 +0000
Re: non-blocking getkey? Christian Gollwitzer <auriocus@gmx.de> - 2015-11-18 10:14 +0100
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 10:39 +0000
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 11:01 +0000
Re: non-blocking getkey? Christian Gollwitzer <auriocus@gmx.de> - 2015-11-18 12:17 +0100
Re: non-blocking getkey? Terry Reedy <tjreedy@udel.edu> - 2015-11-18 07:26 -0500
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 13:06 +0000
Re: non-blocking getkey? Chris Angelico <rosuav@gmail.com> - 2015-11-19 00:24 +1100
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 13:57 +0000
Re: non-blocking getkey? Steven D'Aprano <steve@pearwood.info> - 2015-11-19 00:38 +1100
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 13:51 +0000
Re: non-blocking getkey? Chris Angelico <rosuav@gmail.com> - 2015-11-19 01:01 +1100
Re: non-blocking getkey? Jussi Piitulainen <harvesting@makes.invalid> - 2015-11-18 16:13 +0200
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-18 16:50 +0000
Re: non-blocking getkey? Terry Reedy <tjreedy@udel.edu> - 2015-11-18 12:55 -0500
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-19 15:48 +0000
Re: non-blocking getkey? Michael Torrie <torriem@gmail.com> - 2015-11-19 09:31 -0700
Re: non-blocking getkey? eryksun <eryksun@gmail.com> - 2015-11-20 02:43 -0600
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-23 17:01 +0000
askopenfilename() (was: Re: non-blocking getkey?) Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-28 10:29 +0000
Re: askopenfilename() Christian Gollwitzer <auriocus@gmx.de> - 2015-11-28 12:45 +0100
Re: askopenfilename() Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-28 12:48 +0000
Re: askopenfilename() Christian Gollwitzer <auriocus@gmx.de> - 2015-11-28 14:34 +0100
Re: askopenfilename() Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-28 16:45 +0000
Re: askopenfilename() Laura Creighton <lac@openend.se> - 2015-11-28 17:02 +0100
Re: askopenfilename() Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-28 16:05 +0000
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-10 08:28 +0000
Re: non-blocking getkey? Christian Gollwitzer <auriocus@gmx.de> - 2015-12-10 09:54 +0100
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-10 10:26 +0000
Re: non-blocking getkey? Christian Gollwitzer <auriocus@gmx.de> - 2015-12-10 09:57 +0100
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-10 10:40 +0000
Re: non-blocking getkey? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-12-10 15:52 +0000
Re: non-blocking getkey? eryksun <eryksun@gmail.com> - 2015-11-18 12:24 -0600
csiph-web