Set a Tkinter window as a background for the others

191 Views Asked by At

I want to make a program with a setup but if the user is clicking in the fullscreen window while the second window is on the screen the second window goes in the back of the fullscreen window and the user needs to restart the program. I would like something oposite from the win.attributes('-topmost',True) command

I don't know anything to fix even if i've searched on google but I get only the oposite. Sorry for my bad english

1

There are 1 best solutions below

5
Thomas On

If I've understood your question correctly, you want a second smaller window (maybe a popup) to not go behind another fullscreen window. You can use wm_attributes('-topmost', True) for this. wm_attributes('-topmost', True) forces the window that has the attribute to be on top of other windows. You can apply it to any window using window_name.wm_attributes('-topmost', True). Below is a basic example of something you could do:

# Imports
import tkinter as tk

# Create the root window
window = tk.Tk()
window.overrideredirect(True)
window.withdraw()

# Create the fullscreen window
fullscreen_window = tk.Toplevel()
fullscreen_window.attributes('-fullscreen', True)

# Create the second window
popup = tk.Toplevel()
popup.geometry('300x200')
popup.wm_attributes('-topmost', True)

# Exit button
exit_button = tk.Button(popup, text="Exit", command=exit)
exit_button.pack()




window.mainloop()