-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tk.py
More file actions
56 lines (47 loc) · 1.36 KB
/
test_tk.py
File metadata and controls
56 lines (47 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# @Time : 2018-09-06 22:24
# @Author : DuQing
# @File : test_tk.py
"""
description
"""
import random
import time
from tkinter import Tk, Canvas
def draw(canvas, width, height, money):
money.sort()
w = width // len(money)
canvas.delete('all')
for index, value in enumerate(money):
if value >= 0:
canvas.create_rectangle(index * w + 2, height / 2 - value, index * w + w - 2, height / 2,
fill='blue')
else:
canvas.create_rectangle(index * w + 2, height / 2, index * w + w - 2, height / 2 - value,
fill='red')
def random_put_get(money):
for i in range(len(money)):
money[i] -= 1
x = random.randint(0, 99)
money[x] += 1
return money
def main():
tk = Tk()
tk.resizable(False, False)
canvas = Canvas(tk, width=1000, height=800)
# canvas.create_rectangle(10,10, 200,200)
# print(canvas.winfo_width())
# print(canvas.winfo_height())
canvas.pack()
money = [100 for i in range(100)]
while True:
try:
for i in range(100):
money = random_put_get(money)
draw(canvas, 1000, 800, money)
tk.update()
time.sleep(0.03)
except Exception as e:
break
# tk.mainloop()
if __name__ == '__main__':
main()