-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.py
63 lines (42 loc) · 1.54 KB
/
window.py
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
57
58
59
60
61
62
63
import tkinter as tk
from sprites import Sprite
from typing import List
from sys import platform
class Window:
root: tk.Tk
sprites = List[Sprite]
current_sprite_index: int
label: tk.Label
def __init__(self):
self.root = tk.Tk()
self.label = tk.Label(self.root)
self.current_sprite_index = 0
self.sprites = list()
self.root.config(highlightbackground='black')
self.root.overrideredirect(True)
self.root.attributes('-topmost', True)
self.root.config(cursor="none")
if platform == "win32":
self.root.wm_attributes('-transparentcolor','black')
else:
self.root.wait_visibility(self.root)
self.root.attributes('-alpha', 0.9)
def add_sprite(self, sprite: Sprite):
self.sprites.append(sprite)
def mainloop(self):
self.label.pack()
self.root.after(0, self.update, 0)
self.root.mainloop()
def set_current_sprite(self, index: int):
if index < len(self.sprites):
self.current_sprite_index = index
def update(self, index: int):
current_sprite: Sprite = self.sprites[self.current_sprite_index]
frame = current_sprite.frames[index]
index += 1
if index == current_sprite.frame_count:
index = 0
self.root.geometry(current_sprite.get_geometry())
self.label.configure(image=frame)
current_sprite.update_sprite_to_mouse()
self.root.after(50, self.update, index)