Reputation: 13
I have a tkinter python 2.x program. I have several windows appearing on the screen. I use buttons to navigate from one to another, but I'm struggling to close a window and refocus on a currently opened window. I can open new windows just fine!
#code for main window
def frmMain():
app = Tk()
app.title("TWS: XML Options")
app.geometry("200x100")
bn1 = Button(app,text="Add", command=frmAdd)
bn1.grid(row = 2,column = 2, stick = W)
bn2 = Button(app,text="Edit", command=frmEdit)
bn2.grid(row = 2,column = 3, stick = W)
bn3 = Button(app,text="Delete", command=frmDelete)
bn3.grid(row = 2,column = 4, stick = W)
bn4 = Button(app,text="Back",command=frmMenu)
bn4.grid(row = 3,column = 2, stick = W)
app.mainloop()
#code for button on sub window
....
bn1 = Button(app,text="Back", command=back)
...
def back():
#Code to close current window and reopen frmMain
Upvotes: 1
Views: 2579
Reputation: 8759
A TopLevel Window can be activated using its deiconify()
method.
Use the basic Widget method focus_set()
to set keyboard focus to a specific widget.
Upvotes: 0