Skip to content

Commit 17c32e6

Browse files
committed
time
1 parent 7cc58da commit 17c32e6

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
3+
import pygame
4+
5+
# --- constants ---
6+
7+
BLACK = ( 0, 0, 0)
8+
WHITE = (255, 255, 255)
9+
10+
# --- main ---
11+
12+
# - init -
13+
14+
pygame.init()
15+
16+
screen = pygame.display.set_mode((800, 600))
17+
18+
# - objects -
19+
20+
# current time
21+
curr_time = pygame.time.get_ticks()
22+
23+
# first time check at once
24+
check_time = curr_time
25+
26+
# other
27+
rect = pygame.Rect(0, 0, 100, 100)
28+
29+
# - mainloop -
30+
31+
clock = pygame.time.Clock()
32+
33+
running = True
34+
35+
while running:
36+
37+
# - events -
38+
39+
for event in pygame.event.get():
40+
if event.type == pygame.QUIT:
41+
running = False
42+
elif event.type == pygame.KEYDOWN:
43+
if event.key == pygame.K_ESCAPE:
44+
running = False
45+
46+
# - updates -
47+
48+
curr_time = pygame.time.get_ticks()
49+
50+
# execute function
51+
if curr_time >= check_time:
52+
print('time to do it')
53+
# check again after 1000ms (1s)
54+
check_time = curr_time + 1000
55+
56+
# other
57+
rect.center = pygame.mouse.get_pos()
58+
59+
# - draws -
60+
61+
screen.fill(BLACK)
62+
pygame.draw.rect(screen, WHITE, rect)
63+
pygame.display.flip()
64+
65+
# - FPS -
66+
67+
clock.tick(30)
68+
69+
# - end -
70+
71+
pygame.quit()

tkinter/subprocess/example-1.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import tkinter as tk
2+
import subprocess
3+
4+
'''Command takes some time so it freezes GUI'''
5+
6+
# --- functions ---
7+
8+
def ping():
9+
# without `shell=True` - cmd as list
10+
cmd = ["ping", "-c", "2", entry.get()]
11+
output = subprocess.check_output(cmd)
12+
13+
# with `shell=True` - cmd as string
14+
#cmd = "ping -c 2 {}".format(entry.get())
15+
#output = subprocess.check_output(cmd, shell=True)
16+
17+
result.insert('end', output.decode('utf-8'))
18+
19+
# --- main ---
20+
21+
root = tk.Tk()
22+
23+
l = tk.Label(root, text="Enter IP or host")
24+
l.pack()
25+
26+
entry = tk.Entry(root, textvariable=entry)
27+
entry.pack()
28+
29+
b = tk.Button(root, text="RUN", command=ping)
30+
b.pack()
31+
32+
result = tk.Text(root)
33+
result.pack()
34+
35+
root.mainloop()

0 commit comments

Comments
 (0)