-
Notifications
You must be signed in to change notification settings - Fork 0
/
Time.py
176 lines (158 loc) · 8.24 KB
/
Time.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
## ----- Import Modules -----##
from tkinter import *
from tkinter import Button, Label
from pathlib import Path
import Main
from pygame import mixer
from Easy import e_path
from Medium import m_path
from Hard import h_path
from Main import icon
## ----- Linked files -----##
button_sound = Path(__file__).parent / "Sound/button_click.mp3"
button_click = mixer.Sound(button_sound)
button_click.set_volume(0.3)
## ----- Main program ----- ##
def time_loop(mute, theme, language):
# Allows to center the window for all screen dimensions
def window_center(width, heigth):
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = (screen_width/2) - (width/2)
y = (screen_height/2) - (heigth/2)
window.geometry('%dx%d+%d+%d' % (width, heigth, x, y))
## ----- Creation of the window ----- ##
window = Tk()
if language == 'french':
window.title('Démineur - Meilleurs temps')
else:
window.title('Minesweeper - Best time')
window_center(864, 744)
window.resizable(False, False)
window.iconbitmap(icon)
def back():
button_click.play()
Main.music_playing += 1
window.destroy()
Main.menu(mute, theme, language)
def enter(name, size, event): # Event come from the bind method
name.configure(bg="#CAB7B9", font=("Small fonts", size+2))
if theme == 'dark':
name.configure(bg="#514154", font=("Small fonts", size+2))
def exit(name, size, event): # Event come from the bind method
name.configure(bg="#E1CCCE", font=("Small fonts", size))
if theme == 'dark':
name.configure(bg="#3E2C41", font=("Small fonts", size))
## ----- Canvas creation -----##
main = Canvas(window, width=859, height=739, bg='#a39193')
main.grid(row=0, column=0, rowspan=10, columnspan=2, sticky=NW)
line1 = main.create_line(
277, 180, 277, 685, width=4, fill="#726566")
line2 = main.create_line(
587, 180, 587, 685, width=4, fill="#726566")
title = Label(window, text=" Démineur ")
title.grid(row=0, column=0, columnspan=1, padx=319, pady=20, sticky=NW)
title.config(font=("Small fonts", 35), bg='#E1CCCE', relief=RIDGE)
subtitle = Label(window, text=" Meilleurs temps ")
subtitle.grid(row=0, column=0, columnspan=1,
padx=288, pady=90, sticky=NW)
subtitle.config(font=("Small fonts", 25, "bold"),
bg='#E1CCCE', relief=RIDGE, foreground="#68228b")
## ---- Information creation -----##
title_easy = Label(window, text=" Classement facile ")
title_easy.grid(row=0, column=0, columnspan=1,
padx=28, pady=180, sticky=NW)
title_easy.config(font=("Small fonts", 17, "bold"),
bg='#E1CCCE', relief=RIDGE, foreground="#00AB14")
# Finding times
with open(str(e_path), "r") as file:
l_score = [tuple(map(int, line.strip().split(',')))
for line in file if line.strip()]
# Sorts according to the best times
l_score.sort(key=lambda x: x[0] * 60 + x[1])
# Best times display
if language == 'french':
line_time_e = Label(window, text='\n'.join(
[f'{i}.) {time_info[0]} minutes et {time_info[1]} secondes'if time_info[0] > 0 else f'{i}.) {time_info[1]} secondes' for i, time_info in enumerate(l_score[:20], 1)]))
elif language == 'english':
line_time_e = Label(window, text='\n'.join(
[f'{i}.) {time_info[0]} minutes and {time_info[1]} seconds'if time_info[0] > 0 else f'{i}.) {time_info[1]} seconds' for i, time_info in enumerate(l_score[:20], 1)]))
line_time_e.grid(row=0, column=0, columnspan=1,
pady=240, padx=13, sticky=NW)
line_time_e.config(font=("Small fonts", 13, "bold"),
bg='#E1CCCE', relief=RIDGE)
title_medium = Label(window, text=" Classement moyen ")
title_medium.grid(row=0, column=0, columnspan=1,
padx=315, pady=180, sticky=NW)
title_medium.config(font=("Small fonts", 17, "bold"),
bg='#E1CCCE', relief=RIDGE, foreground="#CE8700")
# Finding times
with open(str(m_path), "r") as file:
l_score = [tuple(map(int, line.strip().split(',')))
for line in file if line.strip()]
# Sorts according to the best times
l_score.sort(key=lambda x: x[0] * 60 + x[1])
# Best times display
if language == 'french':
line_time_m = Label(window, text='\n'.join(
[f'{i}.) {temps_info[0]} minutes et {temps_info[1]} secondes'if temps_info[0] > 0 else f'{i}.) {temps_info[1]} secondes' for i, temps_info in enumerate(l_score[:20], 1)]))
elif language == 'english':
line_time_m = Label(window, text='\n'.join(
[f'{i}.) {temps_info[0]} minutes and {temps_info[1]} seconds'if temps_info[0] > 0 else f'{i}.) {temps_info[1]} seconds' for i, temps_info in enumerate(l_score[:20], 1)]))
line_time_m.grid(row=0, column=0, columnspan=1,
pady=240, padx=310, sticky=NW)
line_time_m.config(font=("Small fonts", 13, "bold"),
bg='#E1CCCE', relief=RIDGE)
title_hard = Label(window, text=" Classement difficile ")
title_hard.grid(row=0, column=0, columnspan=1,
padx=603, pady=180, sticky=NW)
title_hard.config(font=("Small fonts", 17, "bold"),
bg='#E1CCCE', relief=RIDGE, foreground="#b22222")
# Finding times
with open(str(h_path), "r") as file:
l_score = [tuple(map(int, line.strip().split(',')))
for line in file if line.strip()]
# Sorts according to the best times
l_score.sort(key=lambda x: x[0] * 60 + x[1])
# Best times display
if language == 'french':
line_time_h = Label(window, text='\n'.join(
[f'{i}.) {temps_info[0]} minutes et {temps_info[1]} secondes'if temps_info[0] > 0 else f'{i}.) {temps_info[1]} secondes' for i, temps_info in enumerate(l_score[:20], 1)]))
elif language == 'english':
line_time_h = Label(window, text='\n'.join(
[f'{i}.) {temps_info[0]} minutes and {temps_info[1]} seconds'if temps_info[0] > 0 else f'{i}.) {temps_info[1]} seconds' for i, temps_info in enumerate(l_score[:20], 1)]))
line_time_h.grid(row=0, column=0, columnspan=1,
pady=240, padx=605, sticky=NW)
line_time_h.config(font=("Small fonts", 13, "bold"),
bg='#E1CCCE', relief=RIDGE)
btn_back = Button(window, width=20, height=1, bg="#E1CCCE", text="RETOUR", font=(
"Small fonts", 15, "bold"), relief=RAISED, borderwidth=3, foreground="black")
btn_back.grid(row=0, pady=690, padx=297, sticky=NW)
btn_back.config(activebackground="#CAB7B9", command=back)
btn_back.bind('<Enter>', lambda event, btn=btn_back: enter(btn, 15, event))
btn_back.bind('<Leave>', lambda event, btn=btn_back: exit(btn, 15, event))
if language == 'english':
title.config(text=' Minesweeper ')
title.grid(row=0, column=0, columnspan=1, padx=273, pady=20, sticky=NW)
subtitle.config(text=' Best time ')
subtitle.grid(row=0, column=0, columnspan=1,
padx=320, pady=90, sticky=NW)
title_easy.config(text=' Easy ranking ')
title_medium.config(text=' Medium ranking ')
title_hard.config(text=' Hard ranking ')
btn_back.config(text="BACK")
if theme == 'dark':
main.config(bg="#261C2C", width=864,
height=744, highlightthickness=0)
title.config(bg="#3E2C41", fg='#e2d8c9')
subtitle .config(bg="#3E2C41", fg='#8806ce')
title_easy.config(
bg="#3E2C41", activebackground="#312334", fg='#00CC18')
title_medium.config(
bg="#3E2C41", activebackground="#312334", fg='#FFA802')
title_hard.config(bg="#3E2C41", fg='#C72626',
activebackground="#312334")
line_time_e.config(bg="#3E2C41", fg='#e2d8c9')
line_time_m.config(bg="#3E2C41", fg='#e2d8c9')
line_time_h.config(bg="#3E2C41", fg='#e2d8c9')
btn_back.config(bg="#3E2C41", fg='#e2d8c9', activebackground="#312334")