Skip to content

Commit 694f376

Browse files
authored
Add files via upload
1 parent b976224 commit 694f376

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed

Cronometro/cronometro_v2.py

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

0 commit comments

Comments
 (0)