Jump to content
Fórum Script Brasil
  • 0

pausar e despausar



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? 



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.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.state = False
                self.display.config(text="%02d:%02d" % (self.mins, self.secs))

                if self.secs == 0:
                    self.mins -= 1
                    self.secs = 59
                    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)

"{: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.

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
    • Total Posts
  • Create New...