Tkinter OSX and "lift"

Discussion in 'Python' started by Miki, Feb 21, 2008.

  1. Miki

    Miki Guest

    Hello,

    Tk.lift doesn't seem to work on OSX (Python 2.5.1).
    The below starts OK, but the window is the behind all other windows.

    from Tkinter import *

    root = Tk()
    Button(root, text="OK", command=root.quit).pack()
    root.lift()
    root.mainloop()

    Any ideas how to tell the window to start as the topmost window?

    Thanks,
    --
    Miki <>
    http://pythonwise.blogspot.com
    Miki, Feb 21, 2008
    #1
    1. Advertising

  2. Miki

    Kevin Walzer Guest

    Miki wrote:
    > Hello,
    >
    > Tk.lift doesn't seem to work on OSX (Python 2.5.1).
    > The below starts OK, but the window is the behind all other windows.
    >
    > from Tkinter import *
    >
    > root = Tk()
    > Button(root, text="OK", command=root.quit).pack()
    > root.lift()
    > root.mainloop()
    >
    > Any ideas how to tell the window to start as the topmost window?
    >
    > Thanks,
    > --
    > Miki <>
    > http://pythonwise.blogspot.com


    If you click on the PythonLauncher application that runs in your dock
    when this script is executed, the window comes into focus fine.

    --
    Kevin Walzer
    Code by Kevin
    http://www.codebykevin.com
    Kevin Walzer, Feb 21, 2008
    #2
    1. Advertising

  3. Miki

    Miki Guest

    Hello Kevin,

    > Tk.lift doesn't seem to work on OSX (Python 2.5.1).
    >> If you click on the PythonLauncher application that runs in your dock
    >> when this script is executed, the window comes into focus fine.

    You're right, but I want to window to be initially in focus (without
    the user clicking on the python launcher icon).

    All the best,
    --
    Miki <>
    http://pythonwise.blogspot.com
    Miki, Feb 21, 2008
    #3
  4. Miki

    Kevin Walzer Guest

    Miki wrote:
    > Hello Kevin,
    >
    >> Tk.lift doesn't seem to work on OSX (Python 2.5.1).
    >>> If you click on the PythonLauncher application that runs in your dock
    >>> when this script is executed, the window comes into focus fine.

    > You're right, but I want to window to be initially in focus (without
    > the user clicking on the python launcher icon).


    "Lift" (which calls the Tk command "raise") doesn't work this way, at
    least not under Aqua. If your application has focus, "lift" will raise
    the widget being called to the top of the stacking order. However, it
    will not make the application frontmost. To do this you'd have to use
    Carbon calls (look at Carbon.CarbonEvt) or use a Tk extension and call
    it from Python. Of course, this is pretty much a non-issue if your
    application is wrapped as a standard Mac application bundle via
    py2app--most Mac users don't run Python apps from the Terminal but
    instead double-click an application icon. In that event, "lift" should
    work fine, because the application will already have focus.

    --
    Kevin Walzer
    Code by Kevin
    http://www.codebykevin.com
    Kevin Walzer, Feb 21, 2008
    #4
  5. Miki

    Miki Guest

    Hello Kevin,

    > "Lift" (which calls the Tk command "raise") doesn't work this way, at
    > least not under Aqua. If your application has focus, "lift" will raise
    > the widget being called to the top of the stacking order. However, it
    > will not make the application frontmost. To do this you'd have to use
    > Carbon calls (look at Carbon.CarbonEvt) or use a Tk extension and call
    > it from Python. Of course, this is pretty much a non-issue if your
    > application is wrapped as a standard Mac application bundle via
    > py2app--most Mac users don't run Python apps from the Terminal but
    > instead double-click an application icon. In that event, "lift" should
    > work fine, because the application will already have focus.


    Thanks,
    --
    Miki <>
    http://pythonwise.blogspot.com
    Miki, Feb 21, 2008
    #5
  6. Miki

    Eric Brunel Guest

    On Thu, 21 Feb 2008 16:53:14 +0100, Kevin Walzer <>
    wrote:
    > Miki wrote:
    >> Hello Kevin,
    >>
    >>> Tk.lift doesn't seem to work on OSX (Python 2.5.1).
    >>>> If you click on the PythonLauncher application that runs in your dock
    >>>> when this script is executed, the window comes into focus fine.

    >> You're right, but I want to window to be initially in focus (without
    >> the user clicking on the python launcher icon).

    >
    > "Lift" (which calls the Tk command "raise") doesn't work this way, at
    > least not under Aqua. If your application has focus, "lift" will raise
    > the widget being called to the top of the stacking order. However, it
    > will not make the application frontmost. To do this you'd have to use
    > Carbon calls (look at Carbon.CarbonEvt) or use a Tk extension and call
    > it from Python. Of course, this is pretty much a non-issue if your
    > application is wrapped as a standard Mac application bundle via
    > py2app--most Mac users don't run Python apps from the Terminal but
    > instead double-click an application icon. In that event, "lift" should
    > work fine, because the application will already have focus.


    There is a trick that sometimes works even for interpreted application:

    import Tkinter as tk
    root = tk.Tk()
    root.withdraw()
    # Code building the window...
    root.lift()
    root.deiconify()
    root.mainloop()

    This sometimes forces the window to be top-most. If this doesn't work, you
    can also try:

    import Tkinter as tk
    root = tk.Tk()
    root.withdraw()
    # Code building the window...
    root.lift()
    root.after_idle(root.deiconify)
    root.mainloop()

    This was a trick that had to be done on Windows a few years back to force
    the main window to be created on top of this others. It deosn't seem to be
    needed anymore now, but maybe the trick can be used on a Mac... Don't know
    if this will work the same, though...

    HTH
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
    Eric Brunel, Feb 22, 2008
    #6
  7. Miki

    Miki Guest

    Hello Eric,

    > >>> Tk.lift doesn't seem to work on OSX (Python 2.5.1).


    > There is a trick that sometimes works even for interpreted application:
    >
    > import Tkinter as tk
    > root = tk.Tk()
    > root.withdraw()
    > # Code building the window...
    > root.lift()
    > root.deiconify()
    > root.mainloop()
    >
    > This sometimes forces the window to be top-most. If this doesn't work, you  
    > can also try:
    >
    > import Tkinter as tk
    > root = tk.Tk()
    > root.withdraw()
    > # Code building the window...
    > root.lift()
    > root.after_idle(root.deiconify)
    > root.mainloop()
    >
    > This was a trick that had to be done on Windows a few years back to force  
    > the main window to be created on top of this others. It deosn't seem to be  
    > needed anymore now, but maybe the trick can be used on a Mac... Don't know  
    > if this will work the same, though...

    Sadly, both of them didn't work.

    Thanks.
    --
    Miki <>
    http://pythonwise.blogspot.com
    Miki, Feb 22, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daren Hawes
    Replies:
    0
    Views:
    313
    Daren Hawes
    Nov 4, 2004
  2. Dean N. Williams

    Installing Python and Tkinter on OSX

    Dean N. Williams, Sep 22, 2003, in forum: Python
    Replies:
    0
    Views:
    324
    Dean N. Williams
    Sep 22, 2003
  3. Leo
    Replies:
    4
    Views:
    349
    Skip Montanaro
    Oct 14, 2003
  4. Ralf Wieseler

    Python on Max osx and tkinter

    Ralf Wieseler, Dec 25, 2003, in forum: Python
    Replies:
    5
    Views:
    1,098
    Ralf Wieseler
    Dec 31, 2003
  5. MichaelW
    Replies:
    1
    Views:
    552
    Kevin Walzer
    Nov 23, 2005
Loading...

Share This Page