Update/renew countdown frame whenever it is raised by tkraise() in tkinter










0















I am trying to create a 2 mins countdown app with multiple windows. I am putting all windows(frames) into the main container, and then use tkraise() to raise the frame whenever the navigation button to specific window is clicked(eg:'startPage' frame will be raised if 'back to startPage' button is clicked).
The code below works well only when the object of class PracticePage was first created.
However, the timer is still running at the back when I navigate from the countdown timer frame(class PracticePage) to another page. In other words, the timer will not count down from 2 mins whenever I navigate from another page back to the countdown timer page. I want it to countdown from 2 mins whenever the timer frame is raised.
I am a beginner in programming. I apologized if my question and code is confusing. Can someone help? Thank you in advance.



Below is my code:



import tkinter as tk
from tkinter import *
from tkinter import ttk
import time

class App(tk.Tk): #we want this class to inherit from tk.Tk
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)

tk.Tk.wm_title(self,"PreSys")

container = tk.Frame(self, height = 1000, width =1000)
container.pack(side="top", fill="both", expand = True)

container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)

self.frames =

for F in (SignInPage, StartPage, PracticePage):

frame = F(container, self)

self.frames[F] = frame

frame.grid(row=0, column=0, sticky="nsew")

self.show_frame(SignInPage)

def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise() #to raise one of the frames up to the front


class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)


self.startButton = ttk.Button(self, text="スタート", command = lambda: controller.show_frame(PracticePage))

self.startButton.pack()

class PracticePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.timeLeft = tk.Label(self,text= "")
self.backButton = ttk.Button(self, text="やり直す", command = lambda: controller.show_frame(StartPage))
self.homeButton = ttk.Button(self, text="サインアウト", command = lambda: controller.show_frame(SignInPage))

self.timeLeft.pack()
self.backButton.pack()
self.homeButton.pack()
#rc.start_record(SignInPage.entry_name.get())

self.remaining = 0
self.countdown(121)

def countdown(self, remaining = None):
if remaining is not None:
self.remaining = remaining

if self.remaining <= 0:
self.timeLeft.configure(text="お疲れ様です!")
else:
mins, secs = divmod(self.remaining,60)
mins = round(mins)
secs = round(secs)
self.timeLeft.configure(text=str(mins) +"分"+ str(secs) +"秒")
self.remaining = self.remaining - 1
self.after(1000, self.countdown)

apps = App()
apps.mainloop()









share|improve this question


























    0















    I am trying to create a 2 mins countdown app with multiple windows. I am putting all windows(frames) into the main container, and then use tkraise() to raise the frame whenever the navigation button to specific window is clicked(eg:'startPage' frame will be raised if 'back to startPage' button is clicked).
    The code below works well only when the object of class PracticePage was first created.
    However, the timer is still running at the back when I navigate from the countdown timer frame(class PracticePage) to another page. In other words, the timer will not count down from 2 mins whenever I navigate from another page back to the countdown timer page. I want it to countdown from 2 mins whenever the timer frame is raised.
    I am a beginner in programming. I apologized if my question and code is confusing. Can someone help? Thank you in advance.



    Below is my code:



    import tkinter as tk
    from tkinter import *
    from tkinter import ttk
    import time

    class App(tk.Tk): #we want this class to inherit from tk.Tk
    def __init__(self, *args, **kwargs):
    tk.Tk.__init__(self, *args, **kwargs)

    tk.Tk.wm_title(self,"PreSys")

    container = tk.Frame(self, height = 1000, width =1000)
    container.pack(side="top", fill="both", expand = True)

    container.grid_rowconfigure(0, weight=1)
    container.grid_columnconfigure(0, weight=1)

    self.frames =

    for F in (SignInPage, StartPage, PracticePage):

    frame = F(container, self)

    self.frames[F] = frame

    frame.grid(row=0, column=0, sticky="nsew")

    self.show_frame(SignInPage)

    def show_frame(self, cont):
    frame = self.frames[cont]
    frame.tkraise() #to raise one of the frames up to the front


    class StartPage(tk.Frame):
    def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)


    self.startButton = ttk.Button(self, text="スタート", command = lambda: controller.show_frame(PracticePage))

    self.startButton.pack()

    class PracticePage(tk.Frame):
    def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.timeLeft = tk.Label(self,text= "")
    self.backButton = ttk.Button(self, text="やり直す", command = lambda: controller.show_frame(StartPage))
    self.homeButton = ttk.Button(self, text="サインアウト", command = lambda: controller.show_frame(SignInPage))

    self.timeLeft.pack()
    self.backButton.pack()
    self.homeButton.pack()
    #rc.start_record(SignInPage.entry_name.get())

    self.remaining = 0
    self.countdown(121)

    def countdown(self, remaining = None):
    if remaining is not None:
    self.remaining = remaining

    if self.remaining <= 0:
    self.timeLeft.configure(text="お疲れ様です!")
    else:
    mins, secs = divmod(self.remaining,60)
    mins = round(mins)
    secs = round(secs)
    self.timeLeft.configure(text=str(mins) +"分"+ str(secs) +"秒")
    self.remaining = self.remaining - 1
    self.after(1000, self.countdown)

    apps = App()
    apps.mainloop()









    share|improve this question
























      0












      0








      0








      I am trying to create a 2 mins countdown app with multiple windows. I am putting all windows(frames) into the main container, and then use tkraise() to raise the frame whenever the navigation button to specific window is clicked(eg:'startPage' frame will be raised if 'back to startPage' button is clicked).
      The code below works well only when the object of class PracticePage was first created.
      However, the timer is still running at the back when I navigate from the countdown timer frame(class PracticePage) to another page. In other words, the timer will not count down from 2 mins whenever I navigate from another page back to the countdown timer page. I want it to countdown from 2 mins whenever the timer frame is raised.
      I am a beginner in programming. I apologized if my question and code is confusing. Can someone help? Thank you in advance.



      Below is my code:



      import tkinter as tk
      from tkinter import *
      from tkinter import ttk
      import time

      class App(tk.Tk): #we want this class to inherit from tk.Tk
      def __init__(self, *args, **kwargs):
      tk.Tk.__init__(self, *args, **kwargs)

      tk.Tk.wm_title(self,"PreSys")

      container = tk.Frame(self, height = 1000, width =1000)
      container.pack(side="top", fill="both", expand = True)

      container.grid_rowconfigure(0, weight=1)
      container.grid_columnconfigure(0, weight=1)

      self.frames =

      for F in (SignInPage, StartPage, PracticePage):

      frame = F(container, self)

      self.frames[F] = frame

      frame.grid(row=0, column=0, sticky="nsew")

      self.show_frame(SignInPage)

      def show_frame(self, cont):
      frame = self.frames[cont]
      frame.tkraise() #to raise one of the frames up to the front


      class StartPage(tk.Frame):
      def __init__(self, parent, controller):
      tk.Frame.__init__(self, parent)


      self.startButton = ttk.Button(self, text="スタート", command = lambda: controller.show_frame(PracticePage))

      self.startButton.pack()

      class PracticePage(tk.Frame):
      def __init__(self, parent, controller):
      tk.Frame.__init__(self, parent)
      self.timeLeft = tk.Label(self,text= "")
      self.backButton = ttk.Button(self, text="やり直す", command = lambda: controller.show_frame(StartPage))
      self.homeButton = ttk.Button(self, text="サインアウト", command = lambda: controller.show_frame(SignInPage))

      self.timeLeft.pack()
      self.backButton.pack()
      self.homeButton.pack()
      #rc.start_record(SignInPage.entry_name.get())

      self.remaining = 0
      self.countdown(121)

      def countdown(self, remaining = None):
      if remaining is not None:
      self.remaining = remaining

      if self.remaining <= 0:
      self.timeLeft.configure(text="お疲れ様です!")
      else:
      mins, secs = divmod(self.remaining,60)
      mins = round(mins)
      secs = round(secs)
      self.timeLeft.configure(text=str(mins) +"分"+ str(secs) +"秒")
      self.remaining = self.remaining - 1
      self.after(1000, self.countdown)

      apps = App()
      apps.mainloop()









      share|improve this question














      I am trying to create a 2 mins countdown app with multiple windows. I am putting all windows(frames) into the main container, and then use tkraise() to raise the frame whenever the navigation button to specific window is clicked(eg:'startPage' frame will be raised if 'back to startPage' button is clicked).
      The code below works well only when the object of class PracticePage was first created.
      However, the timer is still running at the back when I navigate from the countdown timer frame(class PracticePage) to another page. In other words, the timer will not count down from 2 mins whenever I navigate from another page back to the countdown timer page. I want it to countdown from 2 mins whenever the timer frame is raised.
      I am a beginner in programming. I apologized if my question and code is confusing. Can someone help? Thank you in advance.



      Below is my code:



      import tkinter as tk
      from tkinter import *
      from tkinter import ttk
      import time

      class App(tk.Tk): #we want this class to inherit from tk.Tk
      def __init__(self, *args, **kwargs):
      tk.Tk.__init__(self, *args, **kwargs)

      tk.Tk.wm_title(self,"PreSys")

      container = tk.Frame(self, height = 1000, width =1000)
      container.pack(side="top", fill="both", expand = True)

      container.grid_rowconfigure(0, weight=1)
      container.grid_columnconfigure(0, weight=1)

      self.frames =

      for F in (SignInPage, StartPage, PracticePage):

      frame = F(container, self)

      self.frames[F] = frame

      frame.grid(row=0, column=0, sticky="nsew")

      self.show_frame(SignInPage)

      def show_frame(self, cont):
      frame = self.frames[cont]
      frame.tkraise() #to raise one of the frames up to the front


      class StartPage(tk.Frame):
      def __init__(self, parent, controller):
      tk.Frame.__init__(self, parent)


      self.startButton = ttk.Button(self, text="スタート", command = lambda: controller.show_frame(PracticePage))

      self.startButton.pack()

      class PracticePage(tk.Frame):
      def __init__(self, parent, controller):
      tk.Frame.__init__(self, parent)
      self.timeLeft = tk.Label(self,text= "")
      self.backButton = ttk.Button(self, text="やり直す", command = lambda: controller.show_frame(StartPage))
      self.homeButton = ttk.Button(self, text="サインアウト", command = lambda: controller.show_frame(SignInPage))

      self.timeLeft.pack()
      self.backButton.pack()
      self.homeButton.pack()
      #rc.start_record(SignInPage.entry_name.get())

      self.remaining = 0
      self.countdown(121)

      def countdown(self, remaining = None):
      if remaining is not None:
      self.remaining = remaining

      if self.remaining <= 0:
      self.timeLeft.configure(text="お疲れ様です!")
      else:
      mins, secs = divmod(self.remaining,60)
      mins = round(mins)
      secs = round(secs)
      self.timeLeft.configure(text=str(mins) +"分"+ str(secs) +"秒")
      self.remaining = self.remaining - 1
      self.after(1000, self.countdown)

      apps = App()
      apps.mainloop()






      python python-3.x tkinter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 1:26









      sttc1998sttc1998

      145




      145






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Before we get to the solution, when you supply your code make sure it works. You removed the SignInPage because it wasn't necessary, but you didn't follow up and remove the other references to it (i.e.- self.show_frame(SignInPage) in App.__init__ and self.homebutton in PracticePage.



          As for your issue with resetting the timer, there are many ways to go about it, but they all come down to the fact that all you are doing is raising frames: you don't include any code that influences countdown based on what frame you are currently switching to.



          Since this is a relatively simple application, I'll suggest the simplest solution: when you raise PracticePage reset its remaining variable. To keep it as easy and consistent as possible, we'll just modify show_frame



          ## You should store variables that are meaningful (you can place this underneath the imports)
          PRACTICETIME = 121

          ## App():
          def show_frame(self, cont):
          frame = self.frames[cont]
          if cont == PracticePage:
          frame.remaining = PRACTICETIME
          frame.tkraise() #to raise one of the frames up to the front


          In a larger application I would recommend either using widget.after_cancel() to stop the countdown completely or simply to destroy and recreate your Pages if reasonable to do so. With this method you may notice a 1-second lag where the PracticePage is still displaying the previous remaining time: if this really bothers you, then I would recommend extracting the code that formats PracticePage.timeLeft into its own function and then calling that function from App.show_frame right after you set remaining.






          share|improve this answer























          • Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

            – sttc1998
            Nov 17 '18 at 5:07











          • When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

            – Reid Ballard
            Nov 17 '18 at 13:08












          • Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

            – Reid Ballard
            Nov 17 '18 at 13:12











          • I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

            – Reid Ballard
            Nov 27 '18 at 19:44










          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',
          autoActivateHeartbeat: false,
          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%2f53330179%2fupdate-renew-countdown-frame-whenever-it-is-raised-by-tkraise-in-tkinter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Before we get to the solution, when you supply your code make sure it works. You removed the SignInPage because it wasn't necessary, but you didn't follow up and remove the other references to it (i.e.- self.show_frame(SignInPage) in App.__init__ and self.homebutton in PracticePage.



          As for your issue with resetting the timer, there are many ways to go about it, but they all come down to the fact that all you are doing is raising frames: you don't include any code that influences countdown based on what frame you are currently switching to.



          Since this is a relatively simple application, I'll suggest the simplest solution: when you raise PracticePage reset its remaining variable. To keep it as easy and consistent as possible, we'll just modify show_frame



          ## You should store variables that are meaningful (you can place this underneath the imports)
          PRACTICETIME = 121

          ## App():
          def show_frame(self, cont):
          frame = self.frames[cont]
          if cont == PracticePage:
          frame.remaining = PRACTICETIME
          frame.tkraise() #to raise one of the frames up to the front


          In a larger application I would recommend either using widget.after_cancel() to stop the countdown completely or simply to destroy and recreate your Pages if reasonable to do so. With this method you may notice a 1-second lag where the PracticePage is still displaying the previous remaining time: if this really bothers you, then I would recommend extracting the code that formats PracticePage.timeLeft into its own function and then calling that function from App.show_frame right after you set remaining.






          share|improve this answer























          • Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

            – sttc1998
            Nov 17 '18 at 5:07











          • When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

            – Reid Ballard
            Nov 17 '18 at 13:08












          • Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

            – Reid Ballard
            Nov 17 '18 at 13:12











          • I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

            – Reid Ballard
            Nov 27 '18 at 19:44















          0














          Before we get to the solution, when you supply your code make sure it works. You removed the SignInPage because it wasn't necessary, but you didn't follow up and remove the other references to it (i.e.- self.show_frame(SignInPage) in App.__init__ and self.homebutton in PracticePage.



          As for your issue with resetting the timer, there are many ways to go about it, but they all come down to the fact that all you are doing is raising frames: you don't include any code that influences countdown based on what frame you are currently switching to.



          Since this is a relatively simple application, I'll suggest the simplest solution: when you raise PracticePage reset its remaining variable. To keep it as easy and consistent as possible, we'll just modify show_frame



          ## You should store variables that are meaningful (you can place this underneath the imports)
          PRACTICETIME = 121

          ## App():
          def show_frame(self, cont):
          frame = self.frames[cont]
          if cont == PracticePage:
          frame.remaining = PRACTICETIME
          frame.tkraise() #to raise one of the frames up to the front


          In a larger application I would recommend either using widget.after_cancel() to stop the countdown completely or simply to destroy and recreate your Pages if reasonable to do so. With this method you may notice a 1-second lag where the PracticePage is still displaying the previous remaining time: if this really bothers you, then I would recommend extracting the code that formats PracticePage.timeLeft into its own function and then calling that function from App.show_frame right after you set remaining.






          share|improve this answer























          • Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

            – sttc1998
            Nov 17 '18 at 5:07











          • When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

            – Reid Ballard
            Nov 17 '18 at 13:08












          • Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

            – Reid Ballard
            Nov 17 '18 at 13:12











          • I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

            – Reid Ballard
            Nov 27 '18 at 19:44













          0












          0








          0







          Before we get to the solution, when you supply your code make sure it works. You removed the SignInPage because it wasn't necessary, but you didn't follow up and remove the other references to it (i.e.- self.show_frame(SignInPage) in App.__init__ and self.homebutton in PracticePage.



          As for your issue with resetting the timer, there are many ways to go about it, but they all come down to the fact that all you are doing is raising frames: you don't include any code that influences countdown based on what frame you are currently switching to.



          Since this is a relatively simple application, I'll suggest the simplest solution: when you raise PracticePage reset its remaining variable. To keep it as easy and consistent as possible, we'll just modify show_frame



          ## You should store variables that are meaningful (you can place this underneath the imports)
          PRACTICETIME = 121

          ## App():
          def show_frame(self, cont):
          frame = self.frames[cont]
          if cont == PracticePage:
          frame.remaining = PRACTICETIME
          frame.tkraise() #to raise one of the frames up to the front


          In a larger application I would recommend either using widget.after_cancel() to stop the countdown completely or simply to destroy and recreate your Pages if reasonable to do so. With this method you may notice a 1-second lag where the PracticePage is still displaying the previous remaining time: if this really bothers you, then I would recommend extracting the code that formats PracticePage.timeLeft into its own function and then calling that function from App.show_frame right after you set remaining.






          share|improve this answer













          Before we get to the solution, when you supply your code make sure it works. You removed the SignInPage because it wasn't necessary, but you didn't follow up and remove the other references to it (i.e.- self.show_frame(SignInPage) in App.__init__ and self.homebutton in PracticePage.



          As for your issue with resetting the timer, there are many ways to go about it, but they all come down to the fact that all you are doing is raising frames: you don't include any code that influences countdown based on what frame you are currently switching to.



          Since this is a relatively simple application, I'll suggest the simplest solution: when you raise PracticePage reset its remaining variable. To keep it as easy and consistent as possible, we'll just modify show_frame



          ## You should store variables that are meaningful (you can place this underneath the imports)
          PRACTICETIME = 121

          ## App():
          def show_frame(self, cont):
          frame = self.frames[cont]
          if cont == PracticePage:
          frame.remaining = PRACTICETIME
          frame.tkraise() #to raise one of the frames up to the front


          In a larger application I would recommend either using widget.after_cancel() to stop the countdown completely or simply to destroy and recreate your Pages if reasonable to do so. With this method you may notice a 1-second lag where the PracticePage is still displaying the previous remaining time: if this really bothers you, then I would recommend extracting the code that formats PracticePage.timeLeft into its own function and then calling that function from App.show_frame right after you set remaining.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 17 '18 at 4:02









          Reid BallardReid Ballard

          959917




          959917












          • Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

            – sttc1998
            Nov 17 '18 at 5:07











          • When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

            – Reid Ballard
            Nov 17 '18 at 13:08












          • Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

            – Reid Ballard
            Nov 17 '18 at 13:12











          • I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

            – Reid Ballard
            Nov 27 '18 at 19:44

















          • Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

            – sttc1998
            Nov 17 '18 at 5:07











          • When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

            – Reid Ballard
            Nov 17 '18 at 13:08












          • Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

            – Reid Ballard
            Nov 17 '18 at 13:12











          • I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

            – Reid Ballard
            Nov 27 '18 at 19:44
















          Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

          – sttc1998
          Nov 17 '18 at 5:07





          Thank You for your reply and recommendations. I did according to your recommendation of extracting PracticePage.timeLeft into own function and called that from App.show_frame. It really works! But I don't understand why it won't work if I put the function in class PracticePage right before I call self.countdown(122) ?

          – sttc1998
          Nov 17 '18 at 5:07













          When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

          – Reid Ballard
          Nov 17 '18 at 13:08






          When you say you're putting the function right before self.countdown(122) do you mean that you are defining it (writing def updatetimeLeft():) inside of PracticePage.__init__ before the last line that says self.countdown(121)?

          – Reid Ballard
          Nov 17 '18 at 13:08














          Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

          – Reid Ballard
          Nov 17 '18 at 13:12





          Also, typing self.countdown(122) in the comment here instead of self.countdown(121) which is in your code illustrates why you should be using variables for these kinds of things. If you wanted to change the starting countdown time you could easily do so by just changing a variable (in my example, PRACTICETIME) instead of having to go back through the code updating it everywhere and hoping you found them all and didn't make a mistake on any o them.

          – Reid Ballard
          Nov 17 '18 at 13:12













          I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

          – Reid Ballard
          Nov 27 '18 at 19:44





          I'm guessing at this point that you've moved on with your app. If you're satisfied with this answer, feel free to click the checkmark to the left to accept it. If there was anything else, just let me know.

          – Reid Ballard
          Nov 27 '18 at 19:44



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330179%2fupdate-renew-countdown-frame-whenever-it-is-raised-by-tkraise-in-tkinter%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

          27

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          Category:Rhetoric