Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42915d4

Browse files
author
mary
committedNov 18, 2023
Add the new Tic Tac Toe app and solved the problem with the hover color for Calculator IOS
1 parent ca322ef commit 42915d4

File tree

18 files changed

+1073
-742
lines changed

18 files changed

+1073
-742
lines changed
 

‎GAMES/TIC_TAC_TOE/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Tic Tac Toe with ttkbootstrap and pygame
2+
3+
Simple and good looking tic tac toe game including sound. The game is only for 2 player, sadly I am not ready
4+
enough to add the AI boot (I don't want to add the random boot :) )
5+
6+
## Description
7+
8+
The game is made only in ttkboostrap and some little pygame for the sound. You can customize this game as you
9+
want. The main thing you can do is to change the color and many things. To see them check the OPTION part.
10+
11+
## Installation
12+
13+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to
14+
install [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/) and the [pygame ](https://www.pygame.org/news)
15+
16+
```bash
17+
pip install ttkboostrap
18+
```
19+
20+
```bash
21+
pip install pygame
22+
```
23+
24+
## Option
25+
26+
The configuration.py file is made in that the information is stored in dictionary/hash-map or like json file.
27+
In this way is very easy to change the color, the font and kind of everthing you want :/ (so be carefull)
28+
29+
## Visual
30+
31+
<img alt="empty" height="200" src="/home/mary/Documents/Marinel_Projects/Apps_GUI/TIC_TAC_TOE/Tic_Tac_Toe.png" width="200"/>
32+
33+
## Contributing
34+
35+
Pull request are wellcome, if you have any advice I am open. If you know to add the AI boot, I will very happy
36+
to add to my code
37+
38+
## License
39+
40+
[GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/)

‎GAMES/TIC_TAC_TOE/Tic_Tac_Toe.png

55.1 KB
Loading

‎GAMES/TIC_TAC_TOE/configuration.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# size of the app
2+
3+
MAIN_SIZE: tuple[int, int] = (800, 900)
4+
5+
# Music
6+
MUSIC_PATH: str = 'media/tictacktoe_sound.mp3'
7+
8+
# Layout BoardScore and BoardGame.
9+
BOARD_SIZE: tuple[int, int] = (3, 3)
10+
BOARD_ROW: list[int] = list(range(BOARD_SIZE[0]))
11+
BOARD_COL: list[int] = list(range(BOARD_SIZE[1]))
12+
13+
BOARD_SCORE_SIZE: tuple[int, int] = (9, 2)
14+
15+
# Style and attributes for widgets.
16+
17+
FRAME_STYLE_SCORE: str = 'BoardScore.TFrame'
18+
FRAME_STYLE_GAME: str = 'BoardGame.TFrame'
19+
BUTTON_BOARD_STYLE: str = 'BoardGame.TButton'
20+
BUTTON_RESET_STYLE: str = 'ResetButton.TButton'
21+
LABEL_SCORE_STYLE: str = 'BoardScore.TLabel'
22+
23+
BOARD_GAME = {
24+
'BACKGROUND': '#1F1F1F',
25+
'BACKGROUND_FRAME': '#375a7f',
26+
'BORDER_COLOR': '#375a7f',
27+
'BORDER_THICKNESS': 0,
28+
'BORDER_WIDTH': 0,
29+
'FONT': 'Arial',
30+
'FONT_SIZE': 110,
31+
'HOVER_COLOR_ACTIVE': '#222222',
32+
'HOVER_COLOR_DISABLED': '#222222',
33+
'JUSTIFY': 'center',
34+
'RELIEF': 'raised',
35+
'TEXT_COLOR_ACTIVE': '#E1D9D1',
36+
'TEXT_COLOR_DISABLED': '#E1D9D1',
37+
'PADX': 3,
38+
'PADY': 3
39+
}
40+
BOARD_SCORE = {
41+
# the layout of the board
42+
'COLUMNS': list(range(10)),
43+
'ROWS': list(range(2)),
44+
45+
# the style and config
46+
'BACKGROUND': '#121212',
47+
'BACKGROUND_LABEL': '#303030',
48+
'FONT': 'Helvetica',
49+
'FONT_SIZE': 34,
50+
'TEXT_COLOR': '#E1D9D1',
51+
'PLAYER_1': {
52+
'text': 'Player X',
53+
'row': 0,
54+
'col': 0,
55+
'columnspan': 3,
56+
},
57+
'PLAYER_2': {
58+
'text': 'Player O',
59+
'row': 0,
60+
'col': 6,
61+
'columnspan': 3,
62+
},
63+
'TIE': {
64+
'text': 'TIE ',
65+
'row': 0,
66+
'col': 4,
67+
'columnspan': 2,
68+
},
69+
'RESET_BUTTON': {
70+
'row': 0,
71+
'col': 9,
72+
'columnspan': 3,
73+
'rowspan': 2,
74+
},
75+
'PLAYER_1_SCORE': {
76+
'row': 1,
77+
'column': 0,
78+
'columnspan': 3,
79+
},
80+
'PLAYER_2_SCORE': {
81+
'row': 1,
82+
'column': 6,
83+
'columnspan': 3,
84+
},
85+
}
86+
RESET_BUTTON = {
87+
'BACKGROUND': '#E74C3C',
88+
'BORDER_COLOR': '#222222',
89+
'BORDER_THICKNESS': 10,
90+
'BORDER_WIDTH': 2,
91+
'FONT': 'Helvetica',
92+
'HOVER_COLOR_ACTIVE': '#E74C3C',
93+
'HOVER_COLOR_DISABLED': '#E74C3C',
94+
'JUSTIFY': 'center',
95+
'RELIEF': 'solid',
96+
'SIZE': 34,
97+
'TEXT_COLOR_ACTIVE': '#E1D9D1',
98+
'TEXT_COLOR_DISABLED': '#E1D9D1',
99+
}

‎GAMES/TIC_TAC_TOE/main.py

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
import os
2+
import sys
3+
import ttkbootstrap as ttk
4+
5+
from tkinter import IntVar
6+
from widgets import BoardGame, BoardScore
7+
from configuration import (
8+
# layout
9+
MAIN_SIZE, BOARD_GAME, BOARD_SCORE, RESET_BUTTON,
10+
# style
11+
FRAME_STYLE_SCORE, FRAME_STYLE_GAME, BUTTON_BOARD_STYLE, BUTTON_RESET_STYLE, LABEL_SCORE_STYLE,
12+
)
13+
14+
# import the modules for windows (it works only on windows)
15+
16+
try:
17+
from ctypes import windll, byref, sizeof, c_int
18+
except Exception:
19+
pass
20+
21+
22+
def path_resource(relative_path: str) -> str:
23+
"""
24+
it take the relative path and return the absolute path of the file from your system, is used for making the
25+
app into a exe file for window
26+
27+
"""
28+
try:
29+
base_path: str = sys._MEIPASS
30+
except Exception:
31+
base_path = os.path.abspath('.')
32+
return os.path.join(base_path, relative_path)
33+
34+
35+
class TicTacToe(ttk.Window):
36+
37+
player_1: IntVar
38+
player_2: IntVar
39+
tie_score: IntVar
40+
41+
def __init__(self):
42+
super().__init__()
43+
44+
self.bind('<Alt-s>', lambda event: self.destroy())
45+
self.title('')
46+
self.set_emtpy_icon()
47+
self.set_title_bar_color()
48+
self.set_window_size(width = MAIN_SIZE[0], height = MAIN_SIZE[1])
49+
50+
# set up the style
51+
self.Style = ttk.Style(theme = 'darkly')
52+
53+
# style for the score/ board_score
54+
self.Style.configure(
55+
56+
background = BOARD_SCORE['BACKGROUND'],
57+
style = FRAME_STYLE_SCORE,
58+
59+
)
60+
61+
self.Style.configure(
62+
63+
background = BOARD_GAME['BACKGROUND_FRAME'],
64+
style = FRAME_STYLE_GAME,
65+
66+
)
67+
68+
self.Style.configure(
69+
70+
background = BOARD_GAME['BACKGROUND'],
71+
bordercolor = BOARD_GAME['BORDER_COLOR'],
72+
borderthickness = BOARD_GAME['BORDER_THICKNESS'],
73+
borderwidth = BOARD_GAME['BORDER_WIDTH'],
74+
font = (BOARD_GAME['FONT'], BOARD_GAME['FONT_SIZE']),
75+
justify = BOARD_GAME['JUSTIFY'],
76+
relief = BOARD_GAME['RELIEF'],
77+
style = BUTTON_BOARD_STYLE,
78+
79+
)
80+
81+
self.Style.map(
82+
83+
style = BUTTON_BOARD_STYLE,
84+
foreground = [
85+
('active', BOARD_GAME['TEXT_COLOR_ACTIVE']),
86+
('disabled', BOARD_GAME['TEXT_COLOR_DISABLED'])
87+
],
88+
background = [
89+
('active', BOARD_GAME['HOVER_COLOR_ACTIVE']),
90+
('disabled', BOARD_GAME['HOVER_COLOR_DISABLED'])
91+
]
92+
)
93+
94+
self.Style.configure(
95+
96+
background = RESET_BUTTON['BACKGROUND'],
97+
bordercolor = RESET_BUTTON['BORDER_COLOR'],
98+
borderthickness = RESET_BUTTON['BORDER_THICKNESS'],
99+
borderwidth = RESET_BUTTON['BORDER_WIDTH'],
100+
font = (RESET_BUTTON['FONT'], RESET_BUTTON['SIZE']),
101+
justify = RESET_BUTTON['JUSTIFY'],
102+
relief = RESET_BUTTON['RELIEF'],
103+
style = BUTTON_RESET_STYLE,
104+
105+
)
106+
self.Style.map(
107+
108+
style = BUTTON_RESET_STYLE,
109+
foreground = [
110+
('active', RESET_BUTTON['TEXT_COLOR_ACTIVE']),
111+
('disabled', RESET_BUTTON['TEXT_COLOR_DISABLED'])
112+
],
113+
background = [
114+
('active', RESET_BUTTON['HOVER_COLOR_ACTIVE']),
115+
('disabled', RESET_BUTTON['HOVER_COLOR_DISABLED'])]
116+
117+
)
118+
119+
self.Style.configure(
120+
121+
background = BOARD_SCORE['BACKGROUND'],
122+
font = (BOARD_SCORE['FONT'], BOARD_SCORE['FONT_SIZE']),
123+
foreground = BOARD_SCORE['TEXT_COLOR'],
124+
style = LABEL_SCORE_STYLE,
125+
126+
)
127+
128+
# set player data
129+
self.player_1 = ttk.IntVar(value = 0)
130+
self.player_2 = ttk.IntVar(value = 0)
131+
self.tie_score = ttk.IntVar(value = 0)
132+
133+
# set widgets
134+
self.board_game = BoardGame(
135+
136+
parent = self,
137+
style_cells = BUTTON_BOARD_STYLE,
138+
style_frame = FRAME_STYLE_GAME,
139+
player_1 = self.player_1,
140+
tie = self.tie_score,
141+
player_2 = self.player_2,
142+
143+
)
144+
145+
self.board_score = BoardScore(
146+
147+
parent = self,
148+
style_labels = LABEL_SCORE_STYLE,
149+
style_frame = FRAME_STYLE_SCORE,
150+
style_button = BUTTON_RESET_STYLE,
151+
player_1 = self.player_1,
152+
tie = self.tie_score,
153+
player_2 = self.player_2,
154+
function = self.clean_board
155+
156+
)
157+
158+
# run
159+
self.mainloop()
160+
161+
def clean_board(self):
162+
"""
163+
It clean the board and reset the score
164+
"""
165+
self.board_game.clean_board()
166+
self.player_1.set(0)
167+
self.player_2.set(0)
168+
self.tie_score.set(0)
169+
170+
def set_emtpy_icon(self) -> None:
171+
"""
172+
It sets the icon to one empty from the title bar
173+
174+
"""
175+
try:
176+
path_image: str = path_resource('image/empty.ico')
177+
self.iconbitmap(path_image)
178+
except Exception:
179+
pass
180+
181+
def set_window_size(self, width: int, height: int) -> None:
182+
"""
183+
It adjust the window size to be in the center of the screen
184+
185+
"""
186+
left = int(self.winfo_screenwidth() / 2 - width / 2)
187+
top = int(self.winfo_screenheight() / 2 - height / 2)
188+
self.geometry(f'{width}x{height}+{left}+{top}')
189+
190+
def set_title_bar_color(self) -> None:
191+
"""
192+
It works only on Windows, not on GNU/Linux and macOS.
193+
"""
194+
try:
195+
HWND = windll.user32.GetParent(self.winfo_id())
196+
DWMWA_ATTRIBUTE: int = 35 # target the title bar
197+
color_tile: int = 0x00030303
198+
windll.dwmapi.DwmSetWindowAttribute(HWND, DWMWA_ATTRIBUTE, byref(c_int(color_tile)), sizeof(c_int))
199+
except Exception:
200+
pass
201+
202+
203+
if __name__ == '__main__':
204+
205+
# starts the game
206+
TicTacToe()
34.3 KB
Binary file not shown.
66.1 KB
Binary file not shown.

‎GAMES/TIC_TAC_TOE/widgets.py

Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
import ttkbootstrap as ttk
2+
from tkinter import IntVar
3+
from pygame import mixer
4+
from configuration import MUSIC_PATH, BOARD_SIZE, BOARD_GAME, BOARD_SCORE, BOARD_ROW, BOARD_COL
5+
6+
7+
def play_sound():
8+
mixer.music.play(loops = 0)
9+
10+
11+
class BoardGame(ttk.Frame):
12+
13+
def __init__(
14+
self, parent, player_1, player_2,
15+
style_cells, style_frame, tie,
16+
):
17+
super().__init__(master = parent, style = style_frame)
18+
# set mixer and the music file
19+
20+
mixer.init()
21+
mixer.music.load(MUSIC_PATH)
22+
23+
# set score
24+
self.o_score = 0
25+
self.t_score = 0
26+
self.x_score = 0
27+
28+
# set player
29+
self.player_1 = player_1
30+
self.player_2 = player_2
31+
self.tie_score = tie
32+
33+
# set board, player list and the player symbol
34+
self.board_position = [
35+
[0, 0, 0],
36+
[0, 0, 0],
37+
[0, 0, 0],
38+
]
39+
self.players_list = ['X', 'O']
40+
self.player = self.players_list[0]
41+
42+
# layout
43+
self.columnconfigure(BOARD_COL, weight = 1, uniform = 'a')
44+
self.rowconfigure(BOARD_ROW, weight = 1, uniform = 'a')
45+
self.pack(expand = True, fill = 'both', side = 'top')
46+
47+
# add the buttons/cells
48+
for rows in range(BOARD_SIZE[0]):
49+
for cols in range(BOARD_SIZE[1]):
50+
self.board_position[rows][cols] = Button(
51+
parent = self,
52+
column = cols,
53+
columnspan = 1,
54+
command = lambda row = rows, column = cols: self.player_move(row = row, column = column),
55+
row = rows,
56+
rowspan = 1,
57+
style_button = style_cells,
58+
text = '',
59+
)
60+
61+
def player_move(self, row: int, column: int) -> None:
62+
"""
63+
It updates the board when the player click the cells and is the hole logic for the board
64+
65+
"""
66+
play_sound()
67+
if self.board_position[row][column]['text'] == "" and self.check_win() is False:
68+
self.round(row = row, column = column)
69+
else:
70+
if self.empty_space() or self.check_win():
71+
self.clean_board()
72+
73+
def round(self, row: int, column: int) -> None:
74+
"""
75+
It check the round if it is X or O round and
76+
check the round if is done and update the score
77+
78+
"""
79+
80+
# The first move is always for the X player
81+
82+
if self.player == self.players_list[0]:
83+
self.round_x(row = row, column = column)
84+
else:
85+
self.round_o(row = row, column = column)
86+
87+
def round_x(self, row: int, column: int) -> None:
88+
"""
89+
Update the board and the score for the X player
90+
91+
"""
92+
self.board_position[row][column]['text'] = self.player
93+
94+
if self.check_win() is False:
95+
self.player = self.players_list[1]
96+
97+
elif self.check_win() is True:
98+
99+
self.player_1.set(self.player_1.get() + 1)
100+
101+
elif self.check_win() == "Tie":
102+
103+
self.tie_score.set(self.tie_score.get() + 1)
104+
105+
def round_o(self, row: int, column: int) -> None:
106+
"""
107+
108+
Update the board and the score for the O player
109+
110+
"""
111+
self.board_position[row][column]['text'] = self.player
112+
113+
if self.check_win() is False:
114+
self.player = self.players_list[0]
115+
116+
elif self.check_win() is True:
117+
self.player_2.set(self.player_2.get() + 1)
118+
119+
elif self.check_win() == "Tie":
120+
self.tie_score.set(self.tie_score.get() + 1)
121+
122+
def check_win(self):
123+
# Check for winning conditions
124+
if self.row_check() or self.column_check():
125+
return True
126+
127+
elif self.check_first_diagonal() or self.check_second_diagonal():
128+
return True
129+
130+
elif self.empty_space():
131+
return 'Tie'
132+
else:
133+
return False
134+
135+
def column_check(self):
136+
137+
for column in range(BOARD_SIZE[1]):
138+
if self.board_position[0][column]['text'] == self.board_position[1][column]['text'] == \
139+
self.board_position[2][column]['text'] != "":
140+
141+
return True
142+
143+
def row_check(self):
144+
145+
for row in range(BOARD_SIZE[0]):
146+
if self.board_position[row][0]['text'] == self.board_position[row][1]['text'] == \
147+
self.board_position[row][2]['text'] != "":
148+
149+
return True
150+
151+
def check_first_diagonal(self) -> bool:
152+
"""
153+
Check the first diagonal of the board, from left to right
154+
155+
"""
156+
if self.board_position[0][0]['text'] == self.board_position[1][1]['text'] == \
157+
self.board_position[2][2]['text'] != "":
158+
159+
return True
160+
161+
def check_second_diagonal(self) -> bool:
162+
"""
163+
Check the first diagonal of the board, from right to left
164+
165+
"""
166+
167+
if self.board_position[0][2]['text'] == self.board_position[1][1]['text'] == \
168+
self.board_position[2][0]['text'] != "":
169+
170+
return True
171+
172+
def empty_space(self) -> bool:
173+
"""
174+
Check the empty space of the board, and return True if is there are no space
175+
176+
"""
177+
spaces: int = 9
178+
for row in range(BOARD_SIZE[0]):
179+
for column in range(BOARD_SIZE[1]):
180+
181+
if self.board_position[row][column]['text'] != '':
182+
spaces -= 1
183+
184+
return True if spaces == 0 else False
185+
186+
def clean_board(self) -> None:
187+
# Clear the button texts and backgrounds
188+
189+
for row in range(BOARD_SIZE[0]):
190+
for column in range(BOARD_SIZE[1]):
191+
192+
self.board_position[row][column]['text'] = ''
193+
194+
195+
class BoardScore(ttk.Frame):
196+
197+
def __init__(
198+
self, parent, style_labels, style_frame, player_1,
199+
tie, player_2, function, style_button,
200+
):
201+
super().__init__(master = parent, style = style_frame)
202+
# data score
203+
self.player_1_score: IntVar = player_1
204+
self.player_2_score: IntVar = player_2
205+
self.tie_score: IntVar = tie
206+
207+
self.columnconfigure(BOARD_SCORE['COLUMNS'], weight = 1, uniform = 'b')
208+
self.rowconfigure(BOARD_SCORE['ROWS'], weight = 1, uniform = 'b')
209+
self.pack(fill = 'both', side = 'bottom')
210+
211+
# show players name
212+
self.player_1 = Label(
213+
parent = self,
214+
text = BOARD_SCORE['PLAYER_1']['text'],
215+
row = BOARD_SCORE['PLAYER_1']['row'],
216+
column = BOARD_SCORE['PLAYER_1']['col'],
217+
columnspan = BOARD_SCORE['PLAYER_1']['columnspan'],
218+
style = style_labels,
219+
)
220+
self.tie = Label(
221+
222+
parent = self,
223+
text = BOARD_SCORE['TIE']['text'],
224+
row = BOARD_SCORE['TIE']['row'],
225+
column = BOARD_SCORE['TIE']['col'],
226+
columnspan = BOARD_SCORE['TIE']['columnspan'],
227+
style = style_labels,
228+
229+
)
230+
231+
self.player_2 = Label(
232+
233+
parent = self,
234+
text = BOARD_SCORE['PLAYER_2']['text'],
235+
row = BOARD_SCORE['PLAYER_2']['row'],
236+
column = BOARD_SCORE['PLAYER_2']['col'],
237+
columnspan = BOARD_SCORE['PLAYER_2']['columnspan'],
238+
style = style_labels,
239+
240+
)
241+
self.reset_button = Button(
242+
243+
parent = self,
244+
text = 'Reset\nGame',
245+
command = function,
246+
row = 0,
247+
column = 9,
248+
columnspan = 3,
249+
rowspan = 2,
250+
style_button = style_button,
251+
252+
)
253+
# show score
254+
self.label_player_1_score = LabelScore(
255+
256+
parent = self,
257+
textvariable = self.player_1_score,
258+
row = 1,
259+
column = 0,
260+
columnspan = 3,
261+
style = style_labels,
262+
263+
)
264+
265+
self.label_tie_score = LabelScore(
266+
267+
parent = self,
268+
textvariable = self.tie_score,
269+
row = 1,
270+
column = 4,
271+
columnspan = 2,
272+
style = style_labels,
273+
274+
)
275+
self.label_player_2_score = LabelScore(
276+
277+
parent = self,
278+
textvariable = self.player_2_score,
279+
row = 1,
280+
column = 6,
281+
columnspan = 3,
282+
style = style_labels,
283+
284+
)
285+
286+
287+
class Button(ttk.Button):
288+
289+
def __init__(
290+
self, parent, text, command, row,
291+
column, columnspan, rowspan, style_button,
292+
):
293+
# set data
294+
super().__init__(
295+
296+
master = parent,
297+
text = text,
298+
command = command,
299+
style = style_button,
300+
301+
)
302+
303+
# set layout
304+
self.grid(
305+
306+
row = row,
307+
column = column,
308+
sticky = 'news',
309+
columnspan = columnspan,
310+
rowspan = rowspan,
311+
padx = BOARD_GAME['PADX'],
312+
pady = BOARD_GAME['PADY'],
313+
)
314+
315+
316+
class Label(ttk.Label):
317+
def __init__(self, parent, text, row, column, columnspan, style, ):
318+
super().__init__(
319+
320+
master = parent,
321+
text = text,
322+
style = style,
323+
anchor = 'center',
324+
325+
)
326+
327+
self.grid(
328+
329+
row = row,
330+
column = column,
331+
sticky = 'news',
332+
columnspan = columnspan,
333+
padx = 10,
334+
pady = 10,
335+
336+
)
337+
338+
339+
class LabelScore(ttk.Label):
340+
def __init__(self, parent, textvariable, row, column, columnspan, style):
341+
super().__init__(
342+
343+
master = parent,
344+
textvariable = textvariable,
345+
style = style,
346+
anchor = 'center',
347+
348+
)
349+
self.grid(
350+
351+
row = row,
352+
column = column,
353+
sticky = 'news',
354+
columnspan = columnspan,
355+
padx = 10,
356+
pady = 10
357+
358+
)

‎Moder_Calculator_IOS/README.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎Moder_Calculator_IOS/calculator.ico

-6.38 KB
Binary file not shown.

‎Moder_Calculator_IOS/configuration.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

‎Moder_Calculator_IOS/empty.ico

-4.19 KB
Binary file not shown.

‎Moder_Calculator_IOS/example.png

-40 KB
Binary file not shown.

‎Moder_Calculator_IOS/main.py

Lines changed: 0 additions & 281 deletions
This file was deleted.

‎Moder_Calculator_IOS/widgets.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎PYTHON APPS/Moder_Calculator_IOS/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# Mordern Looking Calculator
22

3-
The calculator has a them like IOS calculator.And is made in Tkinter with [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/).The app it will look different on windows and Linux/Macos.
4-
3+
The calculator has a them like IOS calculator.And is made in Tkinter
4+
with [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/).
5+
The app it will look different on windows and Linux/Macos.
56

67
## Installation
78

8-
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/) and pillow 9.5.0.
9+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to
10+
install [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/)
911

1012
```bash
1113
pip install ttkboostrap
1214
```
13-
```bash
14-
pip install pillow==9.5.0
15-
```
1615

1716
## Contributing
1817

19-
Any advice are wellcome.
18+
Any advice are wellcome. :)
2019

2120
## License
2221

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
Here are the settings for the app and the layout.
3-
You can change the settings below, I used a dictionary format.
2+
Here are the settings for the app and the layout.
3+
You can change the settings below, I used a dictionary format.
44
"""
55
# Size and layout app
66

7-
APP_SIZE: list[int] = (600, 800)
7+
APP_SIZE: tuple[int, int] = (600, 800)
88
MAIN_ROW: int = 7
99
MAIN_COLUMN: int = 4
1010

@@ -14,36 +14,36 @@
1414
BUTTON_FONT_SIZE: int = 0
1515

1616
NUMBER_POSITIONS: dict[str, str] = {
17-
18-
'0': {'row': 6, 'column': 0, 'span': 2},
19-
'.': {'row': 6, 'column': 2, 'span': 1},
20-
'1': {'row': 5, 'column': 0, 'span': 1},
21-
'2': {'row': 5, 'column': 1, 'span': 1},
22-
'3': {'row': 5, 'column': 2, 'span': 1},
23-
'4': {'row': 4, 'column': 0, 'span': 1},
24-
'5': {'row': 4, 'column': 1, 'span': 1},
25-
'6': {'row': 4, 'column': 2, 'span': 1},
26-
'7': {'row': 3, 'column': 0, 'span': 1},
27-
'8': {'row': 3, 'column': 1, 'span': 1},
28-
'9': {'row': 3, 'column': 2, 'span': 1},
29-
}
17+
18+
'0': {'row': 6, 'column': 0, 'span': 2},
19+
'.': {'row': 6, 'column': 2, 'span': 1},
20+
'1': {'row': 5, 'column': 0, 'span': 1},
21+
'2': {'row': 5, 'column': 1, 'span': 1},
22+
'3': {'row': 5, 'column': 2, 'span': 1},
23+
'4': {'row': 4, 'column': 0, 'span': 1},
24+
'5': {'row': 4, 'column': 1, 'span': 1},
25+
'6': {'row': 4, 'column': 2, 'span': 1},
26+
'7': {'row': 3, 'column': 0, 'span': 1},
27+
'8': {'row': 3, 'column': 1, 'span': 1},
28+
'9': {'row': 3, 'column': 2, 'span': 1},
29+
}
3030
MATH_POSITIONS: dict[str] = {
31-
'=': {'row': 6, 'column': 3, 'text': '=', 'span': 1},
32-
'+': {'row': 5, 'column': 3, 'text': '+', 'span': 1},
33-
'—': {'row': 4, 'column': 3, 'text': '-', 'span': 1},
34-
'X': {'row': 3, 'column': 3, 'text': '*', 'span': 1},
35-
'/': {'row': 2, 'column': 3, 'text': '/', 'span': 1},
36-
}
31+
'=': {'row': 6, 'column': 3, 'text': '=', 'symbol': '=', 'span': 1},
32+
'+': {'row': 5, 'column': 3, 'text': '+', 'symbol': '+', 'span': 1},
33+
'—': {'row': 4, 'column': 3, 'text': '-', 'symbol': '—', 'span': 1},
34+
'X': {'row': 3, 'column': 3, 'text': '*', 'symbol': 'X', 'span': 1},
35+
'/': {'row': 2, 'column': 3, 'text': '/', 'symbol': ', 'span': 1},
36+
}
3737
MATH_OPERATORS: dict[str] = {
38-
'clear' : {'row': 2, 'column': 0, 'span': 1, 'text': 'AC', },
39-
'invert' : {'row': 2, 'column': 1, 'span': 1, 'text': '+/-'},
40-
'percent': {'row': 2, 'column': 2, 'span': 1, 'text': '%', }
41-
}
38+
'clear': {'row': 2, 'column': 0, 'span': 1, 'text': 'AC', },
39+
'invert': {'row': 2, 'column': 1, 'span': 1, 'text': '+/-'},
40+
'percent': {'row': 2, 'column': 2, 'span': 1, 'text': '%', }
41+
}
4242

4343
GAP_SIZE: int = 1
4444
TITLE_BAR_COLOR: dict[str, int] = {
45-
'dark' : 0x00000000,
46-
'light': 0xFFEEEE
47-
}
45+
'dark': 0x00000000,
46+
'light': 0xFFEEEE
47+
}
4848
BLACK: str = '#000000'
4949
WHITE: str = '#EEEEEE'

‎PYTHON APPS/Moder_Calculator_IOS/main.py

Lines changed: 291 additions & 257 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,68 @@
11
"""
2-
You need to install the ttkbootstrap, pip install ttkbootstrap(I recomand to use a virtual environment)
2+
You need to install the ttkbootstrap, pip install ttkbootstrap(I recomand to use a virtual environment)
33
"""
44
import ttkbootstrap as ttk
55
from configuration import GAP_SIZE
66

77

88
class OutputLabel(ttk.Label):
99
"""
10-
Label for result and formula
11-
"""
10+
Label for result and formula
11+
12+
"""
1213

1314
def __init__(self, parent, style: str, string_var, row: int, anchor: str, column: int = 0) -> None:
1415
super().__init__(
15-
master = parent,
16-
style = style,
17-
textvariable = string_var,
18-
)
16+
master = parent,
17+
style = style,
18+
textvariable = string_var,
19+
)
1920
self.grid(
20-
row = row,
21-
column = column,
22-
columnspan = 4,
23-
sticky = anchor
24-
)
21+
row = row,
22+
column = column,
23+
columnspan = 4,
24+
sticky = anchor
25+
)
2526

2627

2728
class Button(ttk.Button):
2829
"""
2930
The class for operators and numbers buttons
30-
"""
31+
"""
3132

32-
def __init__(self, parent, text: str, func, row: int, column: int, span: int, style: str) -> None:
33+
def __init__(
34+
self, parent, text: str, func, row: int, column: int, span: int, style: str
35+
) -> None:
3336
super().__init__(
34-
master = parent,
35-
text = text,
36-
style = style,
37-
command = func
38-
)
37+
master = parent,
38+
text = text,
39+
style = style,
40+
command = func
41+
)
3942
self.grid(
40-
row = row,
41-
column = column,
42-
columnspan = span,
43-
sticky = 'news',
44-
padx = GAP_SIZE,
45-
pady = GAP_SIZE
46-
47-
)
43+
row = row,
44+
column = column,
45+
columnspan = span,
46+
sticky = 'news',
47+
padx = GAP_SIZE,
48+
pady = GAP_SIZE
49+
50+
)
4851

4952

5053
class NumberButtons(Button):
51-
def __init__(self, parent, text: str, style: str, func: str, row: int, column: int, span: int) -> None:
54+
def __init__(
55+
self, parent, text: str, style: str,
56+
func: str, row: int, column: int, span: int
57+
) -> None:
5258
super().__init__(
53-
parent = parent,
54-
text = text,
55-
style = style,
56-
func = lambda: func(text),
57-
span = span,
58-
row = row,
59-
column = column
60-
)
59+
parent = parent,
60+
text = text,
61+
style = style,
62+
func = lambda: func(text),
63+
span = span,
64+
row = row,
65+
column = column
66+
)
67+
68+

0 commit comments

Comments
 (0)
Please sign in to comment.