The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 115,002     Votes:  2 
Tags: python   tkinter   focus  
Link: 🔍 See Original Answer on Stack Overflow ⧉ 🔗

URL: https://stackoverflow.com/q/63238973
Title: How to make a Tkinter window jump to the front?
ID: /2020/08/04/How-to-make-a-Tkinter-window-jump-to-the-front_
Created: August 4, 2020
Upload: March 26, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


This answer is to make one Tkinter Window pop up overtop of other Tkinter windows.

In my app I have a large window toplevel which calls a much smaller window top2 which initially appears on top of toplevel.

If user clicks within toplevel window it gains focus and smothers much smaller top2 window until toplevel window is dragged off of it.

The solution is to click the button in toplevel to launch top2 again. The top2 open function knows it is already running so simply lifts it to the top and gives it focus:

def play_items(self):
    ''' Play 1 or more songs in listbox.selection(). Define buttons:
            Close, Pause, Prev, Next, Commercial and Intermission
    '''

    if self.top2_is_active is True:
        self.top2.focus_force()     # Get focus
        self.top2.lift()            # Raise in stacking order
        root.update()
        return                      # Don't want to start playing again
⇧ MainThread unfamiliar process suddenly showing up 18.04 PIL Issue, OSError: cannot open resource  ⇩