Switching through different screens using logic in mainloop?
up vote
0
down vote
favorite
I am trying to make a program with three screens with Tkinter, where pressing the button would change to the next screen. Here is a simplified example of the code I am trying to run.
Basically every time the mainloop is run, the program is testing based on the state of the variables scr1, scr2, and scr3 which screen should be displayed at that time.
I have tested that the functions are defined properly (i.e. the values of the variables scr1, scr2, and scr3 are being updated. However, I believe there is an issue regarding what happens after the functions GoToScreenTwo or GoToScreenThree are run (the program doesn't seem to be going back to the mainloop).
import tkinter as tk
scr1 = 1
scr2 = 0
scr3 = 0
def GoToSecondScreen():
global scr1
scr1 = 0
global scr2
scr2 = 1
return()
def GoToThirdScreen():
global scr2
scr2 = 0
global scr3
scr3 = 1
return()
def screen1():
button1 = tk.Button(text="Begin", command = lambda: GoToSecondScreen())
button1.grid()
def screen2():
button1.grid_forget()
button2 = tk.Button(text="Screen 2", command = lambda: GoToThirdScreen())
button2.grid()
def screen3():
button2.grid_forget()
button3 = tk.Button(text="Screen 3")
button3.grid()
root = tk.Tk()
if scr1 == 1 and scr2 == 0 and scr3 == 0:
screen1()
elif scr1 == 0 and scr2 == 1 and scr3 == 0:
screen2()
elif scr3 == 1 and scr1 == 0 and scr2 == 0:
screen3()
tk.mainloop()
python python-3.x tkinter
add a comment |
up vote
0
down vote
favorite
I am trying to make a program with three screens with Tkinter, where pressing the button would change to the next screen. Here is a simplified example of the code I am trying to run.
Basically every time the mainloop is run, the program is testing based on the state of the variables scr1, scr2, and scr3 which screen should be displayed at that time.
I have tested that the functions are defined properly (i.e. the values of the variables scr1, scr2, and scr3 are being updated. However, I believe there is an issue regarding what happens after the functions GoToScreenTwo or GoToScreenThree are run (the program doesn't seem to be going back to the mainloop).
import tkinter as tk
scr1 = 1
scr2 = 0
scr3 = 0
def GoToSecondScreen():
global scr1
scr1 = 0
global scr2
scr2 = 1
return()
def GoToThirdScreen():
global scr2
scr2 = 0
global scr3
scr3 = 1
return()
def screen1():
button1 = tk.Button(text="Begin", command = lambda: GoToSecondScreen())
button1.grid()
def screen2():
button1.grid_forget()
button2 = tk.Button(text="Screen 2", command = lambda: GoToThirdScreen())
button2.grid()
def screen3():
button2.grid_forget()
button3 = tk.Button(text="Screen 3")
button3.grid()
root = tk.Tk()
if scr1 == 1 and scr2 == 0 and scr3 == 0:
screen1()
elif scr1 == 0 and scr2 == 1 and scr3 == 0:
screen2()
elif scr3 == 1 and scr1 == 0 and scr2 == 0:
screen3()
tk.mainloop()
python python-3.x tkinter
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to make a program with three screens with Tkinter, where pressing the button would change to the next screen. Here is a simplified example of the code I am trying to run.
Basically every time the mainloop is run, the program is testing based on the state of the variables scr1, scr2, and scr3 which screen should be displayed at that time.
I have tested that the functions are defined properly (i.e. the values of the variables scr1, scr2, and scr3 are being updated. However, I believe there is an issue regarding what happens after the functions GoToScreenTwo or GoToScreenThree are run (the program doesn't seem to be going back to the mainloop).
import tkinter as tk
scr1 = 1
scr2 = 0
scr3 = 0
def GoToSecondScreen():
global scr1
scr1 = 0
global scr2
scr2 = 1
return()
def GoToThirdScreen():
global scr2
scr2 = 0
global scr3
scr3 = 1
return()
def screen1():
button1 = tk.Button(text="Begin", command = lambda: GoToSecondScreen())
button1.grid()
def screen2():
button1.grid_forget()
button2 = tk.Button(text="Screen 2", command = lambda: GoToThirdScreen())
button2.grid()
def screen3():
button2.grid_forget()
button3 = tk.Button(text="Screen 3")
button3.grid()
root = tk.Tk()
if scr1 == 1 and scr2 == 0 and scr3 == 0:
screen1()
elif scr1 == 0 and scr2 == 1 and scr3 == 0:
screen2()
elif scr3 == 1 and scr1 == 0 and scr2 == 0:
screen3()
tk.mainloop()
python python-3.x tkinter
I am trying to make a program with three screens with Tkinter, where pressing the button would change to the next screen. Here is a simplified example of the code I am trying to run.
Basically every time the mainloop is run, the program is testing based on the state of the variables scr1, scr2, and scr3 which screen should be displayed at that time.
I have tested that the functions are defined properly (i.e. the values of the variables scr1, scr2, and scr3 are being updated. However, I believe there is an issue regarding what happens after the functions GoToScreenTwo or GoToScreenThree are run (the program doesn't seem to be going back to the mainloop).
import tkinter as tk
scr1 = 1
scr2 = 0
scr3 = 0
def GoToSecondScreen():
global scr1
scr1 = 0
global scr2
scr2 = 1
return()
def GoToThirdScreen():
global scr2
scr2 = 0
global scr3
scr3 = 1
return()
def screen1():
button1 = tk.Button(text="Begin", command = lambda: GoToSecondScreen())
button1.grid()
def screen2():
button1.grid_forget()
button2 = tk.Button(text="Screen 2", command = lambda: GoToThirdScreen())
button2.grid()
def screen3():
button2.grid_forget()
button3 = tk.Button(text="Screen 3")
button3.grid()
root = tk.Tk()
if scr1 == 1 and scr2 == 0 and scr3 == 0:
screen1()
elif scr1 == 0 and scr2 == 1 and scr3 == 0:
screen2()
elif scr3 == 1 and scr1 == 0 and scr2 == 0:
screen3()
tk.mainloop()
python python-3.x tkinter
python python-3.x tkinter
edited Nov 10 at 22:40
eyllanesc
69k93052
69k93052
asked Nov 10 at 22:30
Kevin Liu
12
12
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244065%2fswitching-through-different-screens-using-logic-in-mainloop%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown