Shubhwins
Shubhwins

Reputation: 3

Top Level Widget Not appearing above the Main widget in customtkinter/tkinter

I am using a top level widget in customtkinter to show an error, but the top level widget goes below the main widget so the user doesn't end up noticing the error. How can I make the top level widget a priority and make it appear in front of the main widget.

here's an example of what's happening-

import customtkinter
    
app=customtkinter.CTk()

if: #something happens
  #do normal function
else: #error happens
  err=customtkinter.CTkToplevel()
  err.geometry("350x100")
  err.title("Error")     
  err.resizable(False,False)
  err.state("normal")
  err.anchor("center")

app.mainloop()

this new top level window is appearing below the main window.

Upvotes: 0

Views: 399

Answers (2)

Shubhwins
Shubhwins

Reputation: 3

"Make the toplevel a transient window of the root window using .wm_transient(), then the toplevel will always be in front of the root window."

Worked for me thanks!

used toplevel.wm_transient(app)

thanks

Upvotes: 0

Suramuthu R
Suramuthu R

Reputation: 1913

I'm not sure where you have declared this conditional statement. If it were declared before the main window ie window = customtinker. CTk(), there are chances for the top level window to open first.

So the foolproof method is declaring the toplevel window inside a function say err_handle(). Another function which was triggered by the main window or it's widget should trigger the function err_handle only if any error occurs.

Upvotes: 0

Related Questions