Advertisement
paulogp

Countdown Timer

May 18th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.24 KB | None | 0 0
  1. __author__ = "paulogp"
  2.  
  3. from tkinter import Tk, Frame, BOTH, Button, Label, StringVar, messagebox
  4.  
  5.  
  6. class Master(Frame):
  7.     def __init__(self, parent):
  8.         """
  9.        Configurações gerais
  10.        :param parent:
  11.        :return:
  12.        """
  13.         frame = Frame.__init__(self, parent, width=510, height=330)
  14.         self.parent = parent
  15.         self.parent.title("4 COUNTDOWN")
  16.         self.pack(fill=BOTH, expand=1)
  17.  
  18.         # máquina 1
  19.         self.time_str_a = StringVar()
  20.         self.time_str_a.set("00:00")
  21.         self.aux_a = 120
  22.         self.label_count_a = Label(self, textvariable=self.time_str_a, font=("helvetica", 40))
  23.         self.label_count_a.place(x=93, y=20)
  24.         self.timer_a = Button(self, text="Máquina 1", command=self.count_down_a)
  25.         self.timer_a.place(x=127, y=90)
  26.  
  27.         # máquina 3
  28.         self.time_str_b = StringVar()
  29.         self.time_str_b.set("00:00")
  30.         self.aux_b = 120
  31.         self.label_count_b = Label(self, textvariable=self.time_str_b, font=("helvetica", 40))
  32.         self.label_count_b.place(x=290, y=20)
  33.         self.timer_b = Button(self, text="Máquina 3", command=self.count_down_b)
  34.         self.timer_b.place(x=325, y=90)
  35.  
  36.         # máquina 2
  37.         self.time_str_c = StringVar()
  38.         self.time_str_c.set("00:00")
  39.         self.aux_c = 120
  40.         self.label_count_c = Label(self, textvariable=self.time_str_c, font=("helvetica", 40))
  41.         self.label_count_c.place(x=93, y=180)
  42.         self.timer_c = Button(self, text="Máquina 2", command=self.count_down_c)
  43.         self.timer_c.place(x=127, y=250)
  44.  
  45.         # máquina 4
  46.         self.time_str_d = StringVar()
  47.         self.time_str_d.set("00:00")
  48.         self.aux_d = 120
  49.         self.label_count_d = Label(self, textvariable=self.time_str_d, font=("helvetica", 40))
  50.         self.label_count_d.place(x=290, y=180)
  51.         self.timer_d = Button(self, text="Máquina 4", command=self.count_down_d)
  52.         self.timer_d.place(x=325, y=250)
  53.  
  54.         # acerca de...
  55.         self.aboutButton = Button(self, text=" ? ", command=self.about)
  56.         self.aboutButton.place(x=5, y=5)
  57.  
  58.     def count_down_a(self):
  59.         """
  60.        Máquina 1 - Contagem decrescente.
  61.        :return:
  62.        """
  63.         self.timer_a.config(state="disabled")
  64.         if self.aux_a == 0:
  65.             self.timer_a.config(state="active")
  66.             self.aux_a = 120
  67.         else:
  68.             self.aux_a -= 1
  69.             sf = "{:02d}:{:02d}".format(*divmod(self.aux_a, 60))
  70.             self.time_str_a.set(sf)
  71.             self.parent.after(1000, self.count_down_a)
  72.  
  73.     def count_down_b(self):
  74.         """
  75.        Máquina 3 - Contagem decrescente.
  76.        :return:
  77.        """
  78.         self.timer_b.config(state="disabled")
  79.         if self.aux_b == 0:
  80.             self.timer_b.config(state="active")
  81.             self.aux_b = 120
  82.         else:
  83.             self.aux_b -= 1
  84.             sf = "{:02d}:{:02d}".format(*divmod(self.aux_b, 60))
  85.             self.time_str_b.set(sf)
  86.             self.parent.after(1000, self.count_down_b)
  87.  
  88.     def count_down_c(self):
  89.         """
  90.        Máquina 2 - Contagem decrescente.
  91.        :return:
  92.        """
  93.         self.timer_c.config(state="disabled")
  94.         if self.aux_c == 0:
  95.             self.timer_c.config(state="active")
  96.             self.aux_c = 120
  97.         else:
  98.             self.aux_c -= 1
  99.             sf = "{:02d}:{:02d}".format(*divmod(self.aux_c, 60))
  100.             self.time_str_c.set(sf)
  101.             self.parent.after(1000, self.count_down_c)
  102.  
  103.     def count_down_d(self):
  104.         """
  105.        Máquina 4 - Contagem decrescente.
  106.        :return:
  107.        """
  108.         self.timer_d.config(state="disabled")
  109.         if self.aux_d == 0:
  110.             self.timer_d.config(state="active")
  111.             self.aux_d = 120
  112.         else:
  113.             self.aux_d -= 1
  114.             sf = "{:02d}:{:02d}".format(*divmod(self.aux_d, 60))
  115.             self.time_str_d.set(sf)
  116.             self.parent.after(1000, self.count_down_d)
  117.  
  118.     def about(self):
  119.         """
  120.        Dialogo com informação do responsável.
  121.        :return:
  122.        """
  123.         messagebox.showwarning("About", "Paulo G.P., 2015.")
  124.  
  125. if __name__ == "__main__":
  126.     root = Tk()
  127.     app = Master(root)
  128.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement