Thread: SetTopWindow

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    3
    Rep Power
    0

    SetTopWindow


    I am calling python through a C++ application, the tkinter window comes up but is behind the mswindow and I need to bring it to the foreground.
    I am using code similar to this (am not at my python pc at the moment so the code may not be exact)

    Code:
    myProc = win32api.GetProcessId()
    win32gui.SetTopWindow(myProc.HWND)
    app.mainloop()
    I am receiving an error with myProc.HWND not being a true handle. I have tried the GetProcess() with no luck either. Has anyone ever solved this problem?
    thanks
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    I don't think you need the win32api for this as Tkinter has it's own methods:
    http://www.pythonware.com/library/tkinter/introduction/x9531-window-management.htm

    But you can get HWND with the Tkinter winfo_id() method. Which I guess can be plugged into win32 calls.

    grim
    Last edited by Grim Archon; October 29th, 2004 at 09:19 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    3
    Rep Power
    0
    Originally Posted by Grim Archon
    I don't think you need the win32api for this as Tkinter has it's own methods:
    http://www.pythonware.com/library/tkinter/introduction/x9531-window-management.htm

    grim
    EDIT: Its a little early for me...I will try all your suggestions first before asking more questions...sorry

    Thankyou for you reply.
    I will look into that however I would appreciate it if you could point me in some direction ( give me the function I should be looking into) because the top window methods I have found with Tkinter only places the window on top of other Tkinter windows, not mswindows...perhaps I am missing something.
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Your right about the raise method on it's own but in combination with focus_force()
    Code:
        mywin = Toplevel()
        
        win32gui.BringWindowToTop(mywin.winfo_id())
        #or ....
        mywin.lift()
        
        mywin.focus_force()
    you should get what you want.

    grimey
    Last edited by Grim Archon; October 30th, 2004 at 03:10 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    3
    Rep Power
    0
    Originally Posted by Grim Archon
    Your right about the raise method on it's own but in combination with focus_force()
    Code:
        mywin = Toplevel()
        
        win32gui.BringWindowToTop(mywin.winfo_id())
        #or ....
        mywin.lift()
        
        mywin.focus_force()
    you should get what you want.

    grimey
    So simple when you see the answer.
    thankyou

IMN logo majestic logo threadwatch logo seochat tools logo