tags:

views:

82

answers:

3

I have a simple script that runs in to the cmd screen, the console screen...

how can I let the console screen always on top? and if it''s possible, re size it?

A: 

If you are creating your own window, you can use Tkinter to create an "always on top" window like so:

from Tkinter import *
root = Tk()
root.wm_attributes("-topmost", 1)
root.mainloop()

And then put whatever you want to have happen within the main loop.

If you are talking about the command prompt window, then you will have to use some Windows-specific utilities to keep that window on top. You can try this script for Autohotkey.

Jesse Dhillon
A: 

To do this with the cmd window, you'll probably have to invoke a lot of win32 calls.

  1. Enumerate all the windows using win32gui.EnumWindows to get the window handles
  2. Find the "window title" that matches how you run your program. For example, doubling clicking on a .py file on my system the window title is "C:\Python26\python.exe". Running it on a command line, it is called c:\Windows\system32\cmd.exe - c:\python26\python.exe test.py
  3. Using the appropriate title get the cmd window handle.
  4. Using win32gui.SetWindowPos make your window a "top-most" window, etc...

mport win32gui, win32process, win32con
import os

windowList = []
win32gui.EnumWindows(lambda hwnd, windowList: windowList.append((win32gui.GetWindowText(hwnd),hwnd)), windowList)
cmdWindow = [i for i in windowList if "c:\python26\python.exe" in i[0].lower()]
win32gui.SetWindowPos(cmdWindow[0][1],win32con.HWND_TOPMOST,0,0,100,100,0) #100,100 is the size of the window
Mark
A: 

@Mark, I've simplify your answer with this:

import win32gui
import win32con

hwnd = win32gui.GetForegroundWindow()
win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,100,100,200,200,0)

thx btw

Shady