-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart1.15.py
More file actions
193 lines (158 loc) · 5.92 KB
/
start1.15.py
File metadata and controls
193 lines (158 loc) · 5.92 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import tkinter as tk
from tkinter import Frame, Button, Label, PhotoImage
from random import choice
import webbrowser
# nice font for application
global global_font
global_font = 'Verdana 9'
counter, hits, accuracy = 0, 0, 0
def count_p():
global counter, hits, accuracy
counter += 1
hits += 1
accuracy = round(((100 / counter) * hits),2)
l4.config(text=counter)
l6.config(text=str(accuracy)+' %')
def count():
global counter, hits, accuracy
counter += 1
hits += 0
try:
accuracy = round(((100 / counter) * hits),2)
except:
ZeroDivisionError('0')
l4.config(text=counter)
l6.config(text=str(accuracy)+' %')
def toplevel1():
top=tk.Toplevel()
top.geometry("600x300+300+250")
top.overrideredirect(1)
top.configure(bg='lightblue')
def check(letter):
if word_print[1] == letter:
button_check.config(bg='green')
count_p()
else:
button_check.config(bg='red')
count()
button_check.after(1500, lambda: button_check.config(bg='lightgray'))
top.after(1650, lambda: top.destroy())
b1 = tk.Button(top, state=tk.DISABLED, command=lambda: check(letter='ch'))
b2 = tk.Button(top, state=tk.DISABLED, command=lambda: check(letter='h'))
b3 = tk.Button(top, state=tk.DISABLED, command=lambda: check(letter='rz'))
b4 = tk.Button(top, state=tk.DISABLED, command=lambda: check(letter='ż'))
b5 = tk.Button(top, state=tk.DISABLED, command=lambda: check(letter='ó'))
b6 = tk.Button(top, state=tk.DISABLED, command=lambda: check(letter='u'))
def change1():
b1['state'] = tk.NORMAL
b2['state'] = tk.NORMAL
def change2():
b3['state'] = tk.NORMAL
b4['state'] = tk.NORMAL
def change3():
b5['state'] = tk.NORMAL
b6['state'] = tk.NORMAL
def dict_word():
with open("proste.txt", "r", encoding='iso-8859-2') as file:
return(choice(file.readlines()).replace('\n', ''))
def symbols():
word = dict_word()
if 'ch' in word:
wordch = word.replace('ch', '_')
change1()
return(wordch, 'ch')
elif 'h' in word:
wordhh = word.replace('h', '_')
change1()
return(wordhh, 'h')
elif 'rz' in word:
wordrz = word.replace('rz', '_')
change2()
return(wordrz, 'rz')
elif 'ż' in word:
wordzz = word.replace('ż', '_')
change2()
return(wordzz, 'ż')
elif 'ó' in word:
wordou = word.replace('ó', '_')
change3()
return(wordou, 'ó')
elif 'u' in word:
worduu = word.replace('u', '_')
change3()
return(worduu, 'u')
word_print = symbols()
label = tk.Label(top, bg='lightblue').pack()
label1 = tk.Label(top, bg='lightblue', relief='sunken', font=("Verdana", 26))
label1.pack(pady='15')
label1.config(text=word_print[0])
image1 = PhotoImage(file='button_ch.png')
image2 = PhotoImage(file='button_hh.png')
image3 = PhotoImage(file='button_rz.png')
image4 = PhotoImage(file='button_zz.png')
image5 = PhotoImage(file='button_uo.png')
image6 = PhotoImage(file='button_uu.png')
b1.config (image = image1)
b2.config (image = image2)
b3.config (image = image3)
b4.config (image = image4)
b5.config (image = image5)
b6.config (image = image6)
b1.image = image1
b2.image = image2
b3.image = image3
b4.image = image4
b5.image = image5
b6.image = image6
b1.place(x='60' , y='90')
b2.place(x='150', y='90')
b3.place(x='226', y='90')
b4.place(x='314', y='90')
b5.place(x='388', y='90')
b6.place(x='468', y='90')
button_check = tk.Button(top, text='SPRAWDŹ', state=tk.DISABLED, font=((),20))
button_check.place(x='236', y='220')
def toplevel2():
top=tk.Toplevel()
top.geometry("600x300+300+250")
top.overrideredirect(1)
top.configure(bg='lightblue')
label = tk.Label(top, bg='lightblue', text='Program ten był tworzony podczas konkursu', font=("Verdana", 20))
label.pack(pady='30')
def dsp2017():
webbrowser.open("http://devstyle.pl/daj-sie-poznac/")
root.destroy()
button = tk.Button(top, text='Quit', command=dsp2017)
image = PhotoImage(file='dsp2017-1.png')
button.config (image = image)
button.image = image
button.place(x='6', y='100')
button = tk.Button(top, text='Naciśnij, aby wrócić do okna głównego aplikacji.', command=top.destroy)
button.place(x='150', y='260')
root = tk.Tk()
root.geometry("600x400+300+150")
root.title("Mistrz ortografii")
# applying font
root.option_add('*Font', global_font)
root.overrideredirect(1)
tf = tk.Frame(root, height='100' ,width='600').pack(side='top')
bf = tk.Frame(root, height='300', width='600', bg='lightblue').pack(side='bottom')
b1 = tk.Button(tf, bg='yellow', text='Wylosuj słowo', command=toplevel1)
b1.place(height='100' ,width='200', x='0', y='0')
b2 = tk.Button(tf, bg='orange', text='O programie', command=toplevel2)
b2.place(height='100' ,width='200', x='200', y='0')
b3 = tk.Button(tf, bg='red', text='Wyjście', command=root.destroy)
b3.place(height='100' ,width='200', x='400', y='0')
l1 = tk.Label(bf, bg='lightblue', text='Wylosuj słowo i sprawdź \nczy wiesz, jak się je pisze.', font=(("Verdana"),16))
l1.place(x='180', y='140')
l2 = tk.Label(bf, bg='lightblue', text='I zostań Mistrzem Ortografii.', font=(("Verdana"),16))
l2.place(x='166', y='290')
l3 = tk.Label(bf, bg='lightblue', text='Ilość wylosowanych słów: ', font=global_font)
l3.place(x='20', y='360')
l4 = tk.Label(bf, bg='lightblue', text=counter)
l4.place(x='180', y='360')
l5 = tk.Label(bf, bg='lightblue', text='Twoja skuteczność: ', font=global_font)
l5.place(x='20', y='380')
l6 = tk.Label(bf, bg='lightblue', text=accuracy)
l6.place(x='180', y='380')
root.mainloop()