Python Shell window

jay graves jaywgraves at gmail.com
Mon Apr 10 16:58:33 EDT 2006


Jay wrote:
> Is their any way of setting wear the Python Shell window appears on the
> screen when I run my program?
>
> I am testing a full screen program with no Window Frame on a comp with
> 2 monitors and I have to keep pressing the <Window> Key to bring the
> Shell to the front and then moving it manually to the other screen
> every time I restart the program.
>
> I would like it to just appear on the other screen from the start.
>
> Any ideas

1.  Do you really want the CMD prompt to show up?  If not, rename your
file from .py to .pyw and it will be hidden.  You'll miss all of the
STD* streams though.

2.  Find the window and move it to the right place.  Here is a script I
use to launch PuTTY  (which has the unfortunate problem of 'hiding' its
title bar below my 'Start' bar which I keep at the top of my screen).
It's convient for me to launch PuTTY from this script but I don't see
any reason why you couldn't add this code to your main function and
find the errand CMD prompt and move it.

(For this you need the win32 extension installed)
------------------------------------------------
import win32gui,os,sys,time

command = r"start putty -load %s"

def moveWindow(hwnd, ignored):
    x = win32gui.GetWindowText(hwnd)
    if x.find('PuTTY') >= 0:
        left,top,right,bottom = win32gui.GetWindowRect(hwnd)
        if top < 30:
            width = right - left
            height = bottom - top
            win32gui.MoveWindow(hwnd,left,top+30,width,height,1)

try:
    p1 = sys.argv[1]
except IndexError:
    #print "you must provide a valid machine name"
    p1 = "opus"

os.system(command % (p1,))
time.sleep(1.0)
win32gui.EnumWindows(moveWindow, None)
------------------------------------------------


HTH..

Jay




More information about the Python-list mailing list