|
| 1 | +# Cronometro |
| 2 | +# @autor: Magno Efren |
| 3 | +# Youtube: https://www.youtube.com/c/MagnoEfren |
| 4 | + |
| 5 | +from tkinter import Canvas, Button, Frame, Label,Tk |
| 6 | + |
| 7 | + |
| 8 | +ventana = Tk() |
| 9 | +ventana.config(bg='black') |
| 10 | +ventana.geometry('500x250') |
| 11 | +ventana.title('Cronometro') |
| 12 | +ventana.minsize(width=500, height=250) |
| 13 | + |
| 14 | + |
| 15 | +ventana.columnconfigure(0,weight=2) |
| 16 | +ventana.rowconfigure(0,weight=2) |
| 17 | +ventana.columnconfigure(1, weight=2) |
| 18 | +ventana.rowconfigure(0, weight=2) |
| 19 | +ventana.columnconfigure(2,weight=2) |
| 20 | +ventana.rowconfigure(0,weight=2) |
| 21 | +ventana.columnconfigure(1,weight=2) |
| 22 | +ventana.rowconfigure(1,weight=1) |
| 23 | +ventana.columnconfigure(1,weight=2) |
| 24 | +ventana.rowconfigure(1,weight=1) |
| 25 | + |
| 26 | + |
| 27 | +frame1 = Frame(ventana) |
| 28 | +frame1.grid(column=0,row=0,sticky='snew') |
| 29 | +frame2 = Frame(ventana) |
| 30 | +frame2.grid(column=1,row=0,sticky='snew') |
| 31 | +frame3 = Frame(ventana) |
| 32 | +frame3.grid(column=2,row=0,sticky='snew') |
| 33 | +frame4 = Frame(ventana, bg='gray10') |
| 34 | +frame4.grid(row=1, columnspan=3, sticky='snew') |
| 35 | +frame5 = Frame(ventana, bg='black') |
| 36 | +frame5.grid(row=2, columnspan=3, sticky='snew') |
| 37 | + |
| 38 | +#--- |
| 39 | + |
| 40 | +frame1.columnconfigure(0, weight=1) |
| 41 | +frame1.rowconfigure(0, weight=1) |
| 42 | +frame2.columnconfigure(0, weight=1) |
| 43 | +frame2.rowconfigure(0, weight=1) |
| 44 | +frame3.columnconfigure(0, weight=1) |
| 45 | +frame3.rowconfigure(0, weight=1) |
| 46 | +frame4.columnconfigure(0, weight=1) |
| 47 | +frame4.rowconfigure(0, weight=1) |
| 48 | +frame5.columnconfigure(0, weight=1) |
| 49 | +frame5.rowconfigure(0, weight=1) |
| 50 | + |
| 51 | + |
| 52 | +canvas1= Canvas(frame1, bg='gray40', width=200, height =200,highlightthickness=0) |
| 53 | +canvas1.grid(column=0,row=0, sticky='nsew') |
| 54 | +canvas2= Canvas(frame2, bg='gray30', width=200, height =200,highlightthickness=0) |
| 55 | +canvas2.grid(column=0,row=0, sticky='nsew') |
| 56 | +canvas3= Canvas(frame3, bg='gray20', width=200, height =200,highlightthickness=0) |
| 57 | +canvas3.grid(column=0,row=0, sticky='nsew') |
| 58 | + |
| 59 | + |
| 60 | +texto1 = canvas1.create_text(1,1, text='0', font=('Arial',12,'bold'), fill= 'White') |
| 61 | +texto2 = canvas2.create_text(1,1, text='0', font=('Arial',12,'bold'), fill= 'White') |
| 62 | +texto3 = canvas3.create_text(1,1, text='0', font=('Arial',12,'bold'), fill= 'White') |
| 63 | + |
| 64 | +texto_minutos = canvas1.create_text(1,1, text='Minutos', |
| 65 | + font=('Arial',12,'bold'), fill= 'White') |
| 66 | +texto_segundos = canvas2.create_text(1,1, text='Segundos', |
| 67 | + font=('Arial',12,'bold'), fill= 'White') |
| 68 | +texto_milisegundos = canvas3.create_text(1,1, text='Milisegundos', |
| 69 | + font=('Arial',10,'bold'), fill= 'White') |
| 70 | + |
| 71 | +circulo1 = canvas1.create_oval(10,10,100,100, outline='red2',width=10) |
| 72 | +circulo2 = canvas2.create_oval(10,10,100,100, outline='medium spring green',width=10) |
| 73 | +circulo3 = canvas3.create_oval(10,10,100,100, outline='magenta2',width=10) |
| 74 | + |
| 75 | + |
| 76 | +mi = 0 |
| 77 | +se = 0 |
| 78 | +ml = 0 |
| 79 | +contar = 0 |
| 80 | +click_lectura = 0 |
| 81 | +clik_stop = 0 |
| 82 | +clik_inicio =0 |
| 83 | + |
| 84 | + |
| 85 | +def iniciar_pausar(): |
| 86 | + global mi, se, ml, contar, clik_stop, clik_inicio |
| 87 | + ml = ml + 1 |
| 88 | + if ml == 999: |
| 89 | + ml = 0 |
| 90 | + se = se + 1 |
| 91 | + if se ==59: |
| 92 | + se = 0 |
| 93 | + mi = mi + 1 |
| 94 | + |
| 95 | + contar = inicio.after(1, iniciar_pausar) |
| 96 | + |
| 97 | + clik_inicio = inicio.grid_forget() |
| 98 | + |
| 99 | + if clik_inicio is None: |
| 100 | + stop.grid(column=0, row=0, padx =10, pady=10, sticky='nsew') |
| 101 | + stop.config(bg= 'orange', text= 'DETENER') |
| 102 | + |
| 103 | + |
| 104 | +def stop_boton(): |
| 105 | + global contar, clik_stop |
| 106 | + |
| 107 | + |
| 108 | + clik_stop = stop.grid_forget() |
| 109 | + if clik_stop is None : |
| 110 | + inicio.grid(column=0, row=0, padx =10, pady=10, sticky='nsew') |
| 111 | + inicio.config(bg= 'aqua', text='CONTINUAR') |
| 112 | + inicio.after_cancel(contar) |
| 113 | + |
| 114 | + |
| 115 | +def vueltas(): |
| 116 | + global mi, se, ml,click_lectura |
| 117 | + |
| 118 | + click_lectura = click_lectura + 1 |
| 119 | + if click_lectura == 1: |
| 120 | + lectura1.config(text='{} → {}:{}:{}'.format(click_lectura, mi,se,ml), |
| 121 | + fg = 'white', bg='gray10') |
| 122 | + elif click_lectura ==2: |
| 123 | + lectura2.config(text='{} → {}:{}:{}'.format(click_lectura, mi,se,ml), |
| 124 | + fg = 'white', bg='gray10') |
| 125 | + elif click_lectura ==3: |
| 126 | + lectura3.config(text='{} → {}:{}:{}'.format(click_lectura, mi,se,ml), |
| 127 | + fg = 'white', bg='gray10') |
| 128 | + elif click_lectura ==4: |
| 129 | + lectura4.config(text='{} → {}:{}:{}'.format(click_lectura, mi,se,ml), |
| 130 | + fg = 'white', bg='gray10') |
| 131 | + elif click_lectura == 5: |
| 132 | + lectura5.config(text='{} → {}:{}:{}'.format(click_lectura, mi,se,ml), |
| 133 | + fg = 'white', bg='gray10') |
| 134 | + elif click_lectura ==6: |
| 135 | + lectura6.config(text='{} → {}:{}:{}'.format(click_lectura, mi,se,ml), |
| 136 | + fg = 'white', bg='gray10') |
| 137 | + click_lectura = 0 |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +def reiniciar(): |
| 143 | + global mi, se, ml, contar, click_lectura |
| 144 | + mi = 0 |
| 145 | + se = 0 |
| 146 | + ml = 0 |
| 147 | + click_lectura = 0 |
| 148 | + inicio.after_cancel(contar) |
| 149 | + lectura1.configure(text='Lectura 1', fg = 'white', bg='gray10') |
| 150 | + lectura2.configure(text='Lectura 2', fg = 'white', bg='gray10') |
| 151 | + lectura3.configure(text='Lectura 3', fg = 'white', bg='gray10') |
| 152 | + lectura4.configure(text='Lectura 4', fg = 'white', bg='gray10') |
| 153 | + lectura5.configure(text='Lectura 5', fg = 'white', bg='gray10') |
| 154 | + lectura6.configure(text='Lectura 6', fg = 'white', bg='gray10') |
| 155 | + |
| 156 | + stop.grid_forget() |
| 157 | + inicio.grid(column=0, row=0, padx =10, pady=10, sticky='nsew') |
| 158 | + inicio.config(bg= 'green2', text='INICIAR') |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | +def coordenadas(): |
| 164 | + x = canvas1.winfo_width() |
| 165 | + y = canvas1.winfo_height() |
| 166 | + |
| 167 | + x1 = int(x - 0.1*x - 0.1*y + 25) |
| 168 | + y1 = int(y - 0.1*x - 0.1*y + 20) |
| 169 | + x2 = int(x - 0.4*x - 0.4*y - 15) |
| 170 | + y2 = int(y - 0.4*x - 0.4*y - 30) |
| 171 | + |
| 172 | + tamano = int( y1*0.2 + x1*0.1 + 10 ) |
| 173 | + tamano_texto = int( y1*0.02 + x1*0.02 + 3 ) |
| 174 | + |
| 175 | + #print(x1, y1, x2, y2) |
| 176 | + canvas1.coords(circulo1, x1,y1,x2,y2) |
| 177 | + canvas2.coords(circulo2, x1,y1,x2,y2) |
| 178 | + canvas3.coords(circulo3, x1,y1,x2,y2) |
| 179 | + |
| 180 | + #cordenas numeros |
| 181 | + z1 = int(x1*0.6- 10) |
| 182 | + z2 = int(y1*0.6 - 10) |
| 183 | + |
| 184 | + #coordenadas texto |
| 185 | + w1 = int(x1*0.49 + 8) |
| 186 | + w2 = int(y1*0.8 + 10) |
| 187 | + |
| 188 | + canvas1.coords(texto1, z1, z2) |
| 189 | + canvas2.coords(texto2, z1, z2) |
| 190 | + canvas3.coords(texto3, z1, z2) |
| 191 | + |
| 192 | + canvas1.itemconfig(texto1, font=('Arial',tamano,'bold'),text= mi) |
| 193 | + canvas2.itemconfig(texto2, font=('Arial',tamano,'bold'),text= se ) |
| 194 | + canvas3.itemconfig(texto2, font=('Arial',tamano,'bold'), text= ml) |
| 195 | + |
| 196 | + canvas1.coords(texto_minutos, w1, w2) |
| 197 | + canvas2.coords(texto_segundos, w1, w2) |
| 198 | + canvas3.coords(texto_milisegundos, w1, w2) |
| 199 | + |
| 200 | + canvas1.itemconfig(texto_minutos, font=('Arial',tamano_texto,'bold')) |
| 201 | + canvas2.itemconfig(texto_segundos, font=('Arial',tamano_texto,'bold')) |
| 202 | + canvas3.itemconfig(texto_milisegundos, font=('Arial',tamano_texto,'bold')) |
| 203 | + |
| 204 | + canvas1.after(1000, coordenadas) |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | +frame4.columnconfigure(0, weight= 1) |
| 209 | +frame4.rowconfigure(0, weight= 1) |
| 210 | +frame4.columnconfigure(1, weight= 1) |
| 211 | +frame4.rowconfigure(0, weight= 1) |
| 212 | +frame4.columnconfigure(2, weight= 1) |
| 213 | +frame4.rowconfigure(0, weight= 1) |
| 214 | +frame4.columnconfigure(3, weight= 1) |
| 215 | +frame4.rowconfigure(0, weight= 1) |
| 216 | +frame4.columnconfigure(4, weight= 1) |
| 217 | +frame4.rowconfigure(0, weight= 1) |
| 218 | +frame4.columnconfigure(5, weight= 1) |
| 219 | +frame4.rowconfigure(0, weight= 1) |
| 220 | + |
| 221 | + |
| 222 | +lectura1 = Label(frame4, text='Lectura 1', fg = 'white', bg='gray10') |
| 223 | +lectura1.grid(column=0,row=0, sticky='nsew') |
| 224 | +lectura2 = Label(frame4, text='Lectura 2', fg = 'white', bg='gray10') |
| 225 | +lectura2.grid(column=1,row=0, sticky='nsew') |
| 226 | +lectura3 = Label(frame4, text='Lectura 3', fg = 'white', bg='gray10') |
| 227 | +lectura3.grid(column=2,row=0, sticky='nsew') |
| 228 | +lectura4 = Label(frame4, text='Lectura 4', fg = 'white', bg='gray10') |
| 229 | +lectura4.grid(column=3,row=0, sticky='nsew') |
| 230 | +lectura5 = Label(frame4, text='Lectura 5', fg = 'white', bg='gray10') |
| 231 | +lectura5.grid(column=4,row=0, sticky='nsew') |
| 232 | +lectura6 = Label(frame4, text='Lectura 6', fg = 'white', bg='gray10') |
| 233 | +lectura6.grid(column=5,row=0, sticky='nsew') |
| 234 | + |
| 235 | +frame5.columnconfigure(0, weight= 1) |
| 236 | +frame5.rowconfigure(0, weight= 1) |
| 237 | +frame5.columnconfigure(1, weight= 1) |
| 238 | +frame5.rowconfigure(0, weight= 1) |
| 239 | +frame5.columnconfigure(2, weight= 1) |
| 240 | +frame5.rowconfigure(0, weight= 1) |
| 241 | + |
| 242 | + |
| 243 | +stop = Button(frame5, text = 'DETENER', relief = "raised",bd=5, bg='orange', |
| 244 | + font=('Arial', 12, 'bold'), width =20, command = stop_boton) |
| 245 | +stop.grid(column=0, row=0, padx =10, pady=10, sticky='nsew') |
| 246 | + |
| 247 | +inicio = Button(frame5, text = 'INICIAR',relief = "raised",bd=5, bg='green2', |
| 248 | + font=('Arial', 12, 'bold'), width =20, command = iniciar_pausar) |
| 249 | +inicio.grid(column=0, row=0, padx =10, pady=10, sticky='nsew') |
| 250 | + |
| 251 | +vuelta = Button(frame5, text = 'VUELTA',relief = "raised", bd=4, bg='blue2', |
| 252 | + font=('Arial', 12, 'bold'), width =20, command = vueltas) |
| 253 | +vuelta.grid(column=1, row=0,padx =10, pady=10, sticky='nsew') |
| 254 | + |
| 255 | +fin = Button(frame5, text = 'RESTABLECER',relief = "raised",bd=4, bg='red2', |
| 256 | + font=('Arial', 12, 'bold'), width =20, command = reiniciar) |
| 257 | +fin.grid(column=2, row=0, padx =10, pady=10, sticky='nsew') |
| 258 | + |
| 259 | + |
| 260 | +coordenadas() |
| 261 | + |
| 262 | +ventana.mainloop() |
| 263 | + |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | + |
| 268 | + |
| 269 | + |
| 270 | + |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
0 commit comments