The following code display a window without the default title bar. This window contains a button that asks the user to select a file. Unfortunatly, when the button is clicked the popup asking the user to select a file appears behind the main window. How can I ensure that the popup appears on top of the window?
Note: if the line window.overrideredirect(True)
is commented, the popup appears on top of the window, but the default title bar is back.
import tkinter as tk
from tkinter import filedialog as fd
def open_file():
model_file = fd.askopenfile(title="Select model", filetypes=(
('model files', '*.pt'),
('All files', '*.*')
))
print(model_file)
if __name__ == '__main__':
window = tk.Tk()
window.geometry("+100+100")
window.overrideredirect(True) # When commented the code works properly.
button = tk.Button(
window, text='Select a file', command=open_file
)
button.grid(row=0, column=0)
# Provide a way to easily exit.
button2 = tk.Button(
window, text='Exit', command=window.quit
)
button2.grid(row=1, column=0)
window.mainloop()