how to make toplevel the main window

50 Views Asked by At

how to transfer a user to the toplevel window when he tries to switch to the main window. and the main window should be inactive.

I tried to find the answer on the internet, but I never found it.

I need functionality, for example, when opening explorer, select a file/folder and try to switch to the application that opened this window.

1

There are 1 best solutions below

0
Emran On

Use the grab.set() method to set the focus on the top window

from tkinter import *


def new_window():
    top = Toplevel()
    top.title("New Window")
    top.grab_set()


root = Tk()
root.title("Main Window")
btn = Button(root, text="Click", command=new_window).pack()
root.mainloop()