How to keep a Tkinter-Dialog on top of all other windows?

Discussion in 'Python' started by =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jul 2, 2003.

  1. Hi!

    I am creating a dialog-box within my application, using tkinter. The
    problem is the following: After the dialogbox is started, the main
    application window comes again to top and the dialogbox is covered by
    the window of the main application and must be "fetched" again via the
    taskbar to continue. Is there a way to "force" the dialogbox on top of
    all other windows? (I'm using MSWindows and Python22)

    The source of my dialogbox-class is the following:

    class NumberEntry:
    def __init__(self):
    import Tkinter
    from Tkconstants import RIDGE
    from Tkconstants import BOTH
    from Tkconstants import BOTTOM
    from Tkconstants import ACTIVE
    from Tkconstants import LEFT
    from Tkconstants import W
    from Tkconstants import E
    self.tk = Tkinter.Tk()
    self.tk.title("My Dialog")
    frame = Tkinter.Frame(self.tk, borderwidth=2)
    frame.pack(fill=BOTH,expand=1)

    label=Tkinter.Label(frame, text="Telefonnummer:")
    label.pack(fill=BOTH,expand=1)

    self.entry = Tkinter.Entry(frame, name="entry")
    self.entry.pack(fill=BOTH,expand=1)

    box = Tkinter.Frame()
    w = Tkinter.Button(box, text="OK", width = 10, command=self.OnOk,
    default = ACTIVE)
    w.pack(side=LEFT, padx=5, pady=5)
    w = Tkinter.Button(box, text="Cancel", width=10,
    command=self.OnCancel)
    w.pack(side=LEFT, padx=5, pady=5)
    box.pack()

    # try to keep focus on current dialog box
    self.tk.focus_set()
    self.tk.mainloop()
    def OnOk(self):
    self.result = self.entry.get()
    self.tk.destroy()
    def OnCancel(self):
    self.tk.destroy()
    result = ""
    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jul 2, 2003
    #1
    1. Advertising

  2. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    Joe Fromm Guest

    "Thomas Nücker" <> wrote in message
    news:...
    > Hi!
    >
    > I am creating a dialog-box within my application, using tkinter. The
    > problem is the following: After the dialogbox is started, the main
    > application window comes again to top and the dialogbox is covered by
    > the window of the main application and must be "fetched" again via the
    > taskbar to continue. Is there a way to "force" the dialogbox on top of
    > all other windows? (I'm using MSWindows and Python22)
    >

    <snip>

    I had a similar problem using Python/tkinter embedded in a Win32 app, and
    never found a truly satisfactory solution. The best I was able to do was
    have the tk window call into my app, passing its window handle (which you
    can get via winfo_id()). In my app I have a timer running - as long as that
    window exists it will keep calling SetWindowPos with the HWND_TOP flag to
    move the Tk window on top of all the app windows. When given the Tk window
    handle you need to hunt up through it's parents until you find a window with
    no parent, and call SetWindowPos on that window.

    If the window being watched no longer exists I just kill the timer and clear
    the window handle.

    I'd love to find a solution that isn't such a grotesque hack.

    Joe Fromm
    Joe Fromm, Jul 2, 2003
    #2
    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. Jarek
    Replies:
    1
    Views:
    915
    Attila Feher
    Sep 18, 2003
  2. Jeff Epler
    Replies:
    0
    Views:
    578
    Jeff Epler
    Jul 2, 2003
  3. dmitrey
    Replies:
    4
    Views:
    1,827
  4. Hidekazu IWAKI
    Replies:
    0
    Views:
    508
    Hidekazu IWAKI
    Dec 15, 2009
  5. joao
    Replies:
    1
    Views:
    71
    Jim Ley
    Jul 8, 2004
Loading...

Share This Page