'Tkinter exiting mainloop when navigating between pages
I have tried various functionality in tkinter to navigate between pages in my GUI. I am trying to achieve a GUI with a next and previous button, which closes one page, and opens another.
def nextPage():
ws.withdraw()
import page2
Where it perfectly takes me to the next page when I add this as a command to a button.
When I try to use this same logic when returning to the page, it does it fine as well.
The problem arises when I try to import page2 for a second time. It ends up exiting the mainloop and closing out of the program.
What am I doing wrong?
Solution 1:[1]
import module effectively brings into your code the module's code. So recommend import at the beginning of your code. Then in your function you refer to the module page2.
import page2
def nextPage():
ws.withdraw()
page2.run()
Your page2 would need to be changed so that its code is inside the function def run(): so that on the first import at the beginning it will not run.
You can test this if you put import at the beginning of your code without changing the module code - you will see page2 run at that point before the rest of your code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
