Jump to content
Fórum Script Brasil
  • 0

pausar e despausar


devilonline

Question

ola
eu estou a constuir uma pequena aplicaçao no tkinder, um cronometro, 
estou aqui um um problema. eu gostava que o botao pausa pausasse o tempo (o que faz) mas tambem que despausasse ao clicar novamente nele. que continuasse o tempo. 

podem me ajudar? 

obrigado

 


import tkinter as tk

class Timer:
    def __init__(self, master):
        self.master = master
        master.title("Pomodoro Timer")

        self.state = False
        self.minutes = 30
        self.seconds = 0

        self.mins = 25
        self.secs = 0

        self.display = tk.Label(master, height=10, width=10, textvariable="")
        self.display.config(text="30:00")
        self.display.grid(row=0, column=0, columnspan=2)

        self.start_button = tk.Button(master, bg="Green", activebackground="Dark Green", text="Start", width=8, height=4, command=self.start)
        self.start_button.grid(row=1, column=0)

        self.pause_button = tk.Button(master, bg="Red", activebackground="Dark Red", text="Pause", width=8, height=4, command=self.pause)
        self.pause_button.grid(row=1, column=1)

    def countdown(self):


        if self.state == True:

            if (self.mins == 0) and (self.secs == 0):
                self.display.config(text="Done!")
                self.state = False
            else:
                self.display.config(text="%02d:%02d" % (self.mins, self.secs))

                if self.secs == 0:
                    self.mins -= 1
                    self.secs = 59
                else:
                    self.secs -= 1

                self.master.after(1000, self.countdown)

    def start(self):
        if not self.state:
            self.state = True
            self.mins = self.minutes


    def pause(self):
        if self.state:
            self.state = False
            self.minutes = self.mins
            self.seconds = self.secs








root = tk.Tk()
my_timer = Timer(root)

root.mainloop()
"{:02} : {:02}".format(10, 0)
 

 

 

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148691
    • Total Posts
      644530
×
×
  • Create New...