Skip to content
Advertisement

I cannot redirect in tkinter program

My aim is to open on the same window when the button is pressed. But when I run the program, it opens in 2 windows at the same time.

I want it to open when the button is pressed.

How can I do it?

JavaScript

Advertisement

Answer

Your Problem is pretty easy. you cant do twice Tk() in your code and any tkinter code should be have one Tk(). so if you want to make another window you will need Toplevel() it’s the same as Tk(). so there are 2 methods to do this:

Method 1 make a Toplevel() in the function:

so you want to open a new window with that button right ? and you dont want to run twice windows in the beginning.

  1. delete your uruns = tk.Tk()

  2. in your function buttonCallBack do this:

JavaScript

the full code:

JavaScript

Method 2(the best) show/hide your another window Toplevel():

to show your Toplevel() use Toplvel.deiconify()

to hide your Toplevel() use Toplvel.withdraw ()

so do this:

JavaScript
Advertisement