How to link multiple window's focuses in tkinter?

190 Views Asked by At

python 3.8.2

Goal: link multiple windows (root and topLevels) together so if one of them is clicked (has focus) all of the topLevels and root come up in front of the unrelated windows on the desktop in other words all of them have focus but not really

I kinda accomplished this but with only the root because if I included the other 2 toplevels to do the same it would be stuck in a loop. Even so now the program cannot focus on the main root and every time root has focus it is passed on to one of the toplevels.

For this I wrote 2 functions and bound the focusIn and focusOut to these functions Functions:

def Focus(event):
    global rootNoFocus
    global rpwNoFocus
    global cswNoFocus
    print(rootNoFocus, rpwNoFocus, cswNoFocus)
    if rootNoFocus == True and rootNoFocus == True and rootNoFocus == True:
        rndPassWin.focus()
        clickerSetupWin.focus()
    
    if event.widget == root:
        rootNoFocus = False
    if event.widget == rndPassWin:
        rpwNoFocus = False
    if event.widget == clickerSetupWin:
        cswNoFocus = False
        
               
def noFocus(event):
    global rootNoFocus
    global rpwNoFocus
    global cswNoFocus
    
    if event.widget == root:
        rootNoFocus = True
    if event.widget == rndPassWin:
        rpwNoFocus = True
    if event.widget == clickerSetupWin:
        cswNoFocus = True

Binding:

root.bind('<FocusIn>', Focus)
root.bind('<FocusOut>', noFocus)
rndPassWin.bind('<FocusOut>', noFocus)
clickerSetupWin.bind('<FocusOut>', noFocus)
0

There are 0 best solutions below