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()











share|improve this question




























    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()











    share|improve this question


























      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()











      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 22:40









      eyllanesc

      69k93052




      69k93052










      asked Nov 10 at 22:30









      Kevin Liu

      12




      12





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues