From ad1681e561a6c669d3545c7e046fac12d2c8b78d Mon Sep 17 00:00:00 2001 From: Andrzej Date: Fri, 2 Apr 2021 03:39:46 +0200 Subject: [PATCH] Splitted to files --- bin/Classess/Field.py | 77 ++++++ bin/Classess/Player.py | 78 ++++++ bin/Classess/__init__.py | 0 bin/Classess/__pycache__/Field.cpython-37.pyc | Bin 0 -> 2047 bytes .../__pycache__/Player.cpython-37.pyc | Bin 0 -> 678 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 129 bytes bin/Classess/test_2.py | 23 ++ bin/Main/__init__.py | 0 bin/Main/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 125 bytes bin/Main/__pycache__/main.cpython-37.pyc | Bin 0 -> 4325 bytes bin/Main/main.py | 182 ++++++++++++++ bin/__init__.py | 0 bin/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 120 bytes bin/__pycache__/main.cpython-37.pyc | Bin 3251 -> 0 bytes bin/main.py | 228 ------------------ 15 files changed, 360 insertions(+), 228 deletions(-) create mode 100644 bin/Classess/Field.py create mode 100644 bin/Classess/Player.py create mode 100644 bin/Classess/__init__.py create mode 100644 bin/Classess/__pycache__/Field.cpython-37.pyc create mode 100644 bin/Classess/__pycache__/Player.cpython-37.pyc create mode 100644 bin/Classess/__pycache__/__init__.cpython-37.pyc create mode 100644 bin/Classess/test_2.py create mode 100644 bin/Main/__init__.py create mode 100644 bin/Main/__pycache__/__init__.cpython-37.pyc create mode 100644 bin/Main/__pycache__/main.cpython-37.pyc create mode 100644 bin/Main/main.py create mode 100644 bin/__init__.py create mode 100644 bin/__pycache__/__init__.cpython-37.pyc delete mode 100644 bin/__pycache__/main.cpython-37.pyc delete mode 100644 bin/main.py diff --git a/bin/Classess/Field.py b/bin/Classess/Field.py new file mode 100644 index 0000000..fa3bb7c --- /dev/null +++ b/bin/Classess/Field.py @@ -0,0 +1,77 @@ +from doctest import master +from tkinter import * + +# from bin.main import PlayerReturn as player +# from bin.main import DrawingLargeImage + +WINDOW_X = 533 + 1200 +WINDOW_Y = 950 +FRAME_WIDTH = 533 +FRAME_HEIGHT = 533 + +# Size of small image +IMAGE_SIZE = 50 + +step = IMAGE_SIZE + 3 + + +class Field(object): + def __init__(self): + self.win = Tk() + self.width = 533 + self.height = 533 + self.image_size = 50 + self.rows = 10 + self.columns = 10 + self.x_start = 3 + self.y_start = 3 + self.state_of_cell_array = [[0 for i in range(3)] for j in range(200)] + self.small_image_array = [[0 for i in range(self.rows)] for j in range(self.columns)] + self.large_image_array = [[0 for i in range(self.rows)] for j in range(self.columns)] + + self.main_frame = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=0) + self.main_frame.pack(anchor=NW) + self.small_field_canvas = Canvas(self.main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, highlightthickness=0, + bg='light gray') + self.small_field_canvas.pack() + self.large_image_canvas = Canvas(self.win, width=WINDOW_X - 533 - 20, height=900, highlightthickness=0, + bg='gray') + self.large_image_canvas.place(x=FRAME_WIDTH + 5, y=3) + + # # Putting images + # def Fill(self): + # x = self.x_start + # y = self.y_start + # + # row = 0 + # column = 0 + # + # # Drawing small images + # for i in range(self.columns): + # for j in range(self.rows): + # small_image_name = self.small_image_array[column][row] + # + # self.small_field_canvas.image = small_image_name + # self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name) + # + # x += self.image_size + self.x_start + # row += 1 + # y += self.image_size + self.y_start + # x = self.x_start + # column += 1 + # row = 0 + # + # # Drawing red/green rectangles + # for el in self.state_of_cell_array: + # if el[0] != 0: + # self.small_field_canvas.create_rectangle(el[0], el[1], el[0] + step - 2, + # el[1] + step - 2, width=3, outline=el[2]) + # + # DrawingLargeImage() + # self.DrawingLargeImage() + + # def DrawingLargeImage(self): + # large_img_name = self.large_image_array[player.current_array_y][player.current_array_x] + # + # self.large_image_canvas.image = large_img_name + # self.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name) diff --git a/bin/Classess/Player.py b/bin/Classess/Player.py new file mode 100644 index 0000000..f5e6b85 --- /dev/null +++ b/bin/Classess/Player.py @@ -0,0 +1,78 @@ +import sys + +WINDOW_X = 533 + 1200 +WINDOW_Y = 950 +FRAME_WIDTH = 533 +FRAME_HEIGHT = 533 + +# Size of small image +IMAGE_SIZE = 50 + + +class Player(object): + def __init__(self): + self.x_start = 3 + self.y_start = 3 + self.current_x = self.x_start + self.current_y = self.y_start + self.step = IMAGE_SIZE + self.x_start + self.current_array_x = 0 + self.current_array_y = 0 + + # def Moving(self, event): + # # Moving + # if event.keysym == "Right": + # if self.current_x + self.step < FRAME_WIDTH: + # self.current_x += self.step + # field.small_field_canvas.delete('all') + # field.large_image_canvas.delete('all') + # self.current_array_x += 1 + # field.Fill() + # self.Rectangle() + # elif self.current_y + self.step < FRAME_HEIGHT: + # self.current_x = self.x_start + # field.small_field_canvas.delete('all') + # field.large_image_canvas.delete('all') + # self.current_array_x = 0 + # self.current_array_y += 1 + # self.current_y += self.step + # field.Fill() + # self.Rectangle() + # elif event.keysym == "Left": + # if self.current_x - self.step >= self.x_start: + # self.current_x -= self.step + # field.small_field_canvas.delete('all') + # field.large_image_canvas.delete('all') + # self.current_array_x -= 1 + # field.Fill() + # self.Rectangle() + # elif self.current_y - self.step >= self.y_start: + # self.current_x = FRAME_WIDTH - self.step + # field.small_field_canvas.delete('all') + # field.large_image_canvas.delete('all') + # self.current_array_x = 9 + # self.current_array_y -= 1 + # self.current_y -= self.step + # field.Fill() + # self.Rectangle() + # elif event.keysym == "Up": + # if self.current_y - self.step >= self.y_start: + # self.current_y -= self.step + # field.small_field_canvas.delete('all') + # field.large_image_canvas.delete('all') + # self.current_array_y -= 1 + # field.Fill() + # self.Rectangle() + # elif event.keysym == "Down": + # if self.current_y + self.step < FRAME_HEIGHT: + # self.current_y += self.step + # field.small_field_canvas.delete('all') + # field.large_image_canvas.delete('all') + # self.current_array_y += 1 + # field.Fill() + # self.Rectangle() + + # # Drawing rectangle + # def Rectangle(self): + # field.small_field_canvas.create_rectangle(self.current_x, self.current_y, self.current_x + self.step - 2, + # self.current_y + self.step - 2, width=3, outline='blue2') diff --git a/bin/Classess/__init__.py b/bin/Classess/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bin/Classess/__pycache__/Field.cpython-37.pyc b/bin/Classess/__pycache__/Field.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b688a201993fdb335c3597de85465a2e4553c45a GIT binary patch literal 2047 zcmd5-Pj4eN6u0MpCV#p~(`{J+T5(_%1O;(KRmIY#Z4Mg{tyCBV8FxHMCY?;Owo5k^ zoEnL}^uRZOBVT}TfW&9;l~XQ=^Bxe-GfA7El|XP|Mt<}B{@TCy?D?o%_7OaP{6@bl z7ZLhZPZo~_%!e?Fgiw89MV(P#| zD8LK_2E)vlB3Oh8!7XJU#8JXRJonLG7lw`{eg`7aHF}N+W*8_q12vfe)M6%3JEIP> zfOj+MF`GG4Bn!;F#{1}6d-&g?E{451Q%@G2qk(g)DQ23&OEe`}mKC`s?=hbhZ*=@B zcvc5Bxz0*AfT*nN`P`z+DmOORY=CUz``Qm^uE+8|!&`{0!O)SabGuEj+Z=4kHCEe1 z%wp>|hOQAnQg3IFa$U)pE;P4++ybOA)q-Of;&mWB^fmh8{x^Uv!?0~AbH2InjHeca zGgmw{teNM%g{P-I=eC$@_=3cL!UzkslmCu{nKsqD*`$-Z*>QQYgxz&K<2(xYkEAMqJcaI1miC!xaN$_tX9`amuPEc>T$z_~x)jNe zhqM3YbNx4++Bxmw^uY*uVWYi^Llq7_5$fK%aNMVx4nu`+3 zA@H)uKHzj1aoujJc<|}tCrxtN+CMo`rF?SKY#kn*1pbi5Dd}okWsPZgu8j7na`tHY z6&0$Mr|Rnan}oT{J8iZ1KRzX&soHYZxz-*hG>jVft{@9uH>dIzmqT_K-vklD9(GpV zI(~p37&TnMCG5jnhjCR|J@sw)tw5|4mQ9HA2^o&qMWXo%JiZzo^uuD*$d?&T8pYzt?vX&IjRCqU7|(*OVf literal 0 HcmV?d00001 diff --git a/bin/Classess/__pycache__/Player.cpython-37.pyc b/bin/Classess/__pycache__/Player.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..580c7ef5a92af93ee8c7149fbbf211e5b2bb347a GIT binary patch literal 678 zcmZ8f!EVz)5S{fpwi^=C0~NnOE(md|5JI%6NqlICXr+KSuoCj1_1dzN3-VvtY0HJqm%7G zvZ?Y6fd*6uRArXSM=rb;wv?uHVYLA}vz0M=QHpE#04vu{jt_>hI7!mj`L@(c z*W1QPV`PQV{}EN6VWcj;-hp|F#s0pC-(-_&@J*U|X616JO?I9yvOyuO)z)UslV2_? z7YUIs@=}N{=2=Px7T}CxFf{XN*2wD*+r%L zGLKA;IBE(04PdFs5vzUd4!4zc(KHz!eVmHV59o_~^5N6LaV)0E(do!_8fO$I!_leP mK?N6Fo?qx$S?fHiMNctQ&_!>XE54)eV5xNE`K+GY=l=j16QN81 literal 0 HcmV?d00001 diff --git a/bin/Classess/__pycache__/__init__.cpython-37.pyc b/bin/Classess/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f6707a646fd60c29c1c7cd609ffa77f13f25b6ae GIT binary patch literal 129 zcmZ?b<>g`kg3gPH2_X70h=2h`Aj1KOi&=m~3PUi1CZpd70>R zlp9l=SWu8!6qA&h7vr3hSX`W1TpSZ0pP83g5+AQuPg`kf>K!yVl7qb9~6oz01O-8?!3`HPe1o2DF)hZ^S(m5ls wC^x1!v7jKeC?+X0FUB_!NW{ly=4F<|$LkeT-r}&y%}*)KNwov%{|v+o0E68eAOHXW literal 0 HcmV?d00001 diff --git a/bin/Main/__pycache__/main.cpython-37.pyc b/bin/Main/__pycache__/main.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c088a3365d8fd393677868e4ffbc55d466727331 GIT binary patch literal 4325 zcma)9&u?2v9iN%^!_SUmCu!OwyJdIj!U`iucMIw+ODVKX+J^`+3;UP!sB%g)Uy2AuF!u{OGgZRhd|$O}$dLq50;Fs^Z3L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L1$XJJ^J3C#| zwdE~0rL`Vqy;^|Vcub|St9zMeE2gHprE3JP0E{ZEt#`v}yH__mwxYaj$XRI1D$nkUBh3(LaiYQaH^IOXp}I}>>al65B2Bf^)C+qssc4Nw^%^b{ zYbuSKow|v;o!?^ECy|4s`3U&kIS7&>YahUCWy=dS|N66%zRf`k5zP@UE4y4CNsd%YvDGK{G_9@`9dqbX^TL z^*i7p^zYf%QRp_|fVhl^hs`I;h@V%6(Dcm2?Jj-dUHVA%F4wAAu(h$d_VHHq$+-7( ztHjK~#WC|tY!Vd~8{N)!+&s`K44SIjRz~-%bL;PdDNT=$lSCQ1c)Cfe%rKzGThi_B z)toQ@!H6!hVKtBQab$+ooVPLJWvjVF=8rgK7;Y6@EGxY1xJZKd9AEedJ533eUTU;D zifSui!R*EzWDrd;7oGxNtJjixnyNHi%^${^%p5LE&DaN(rcl)%5x7O*hXj5E5SBJ> zU%9a!-P;J)^N6G8fPKtm+}Ougt_!*d=9R;`C&fwbqvU3mS6!jriHF*rtr)?j{Ec~; qN?S@51{no;rA&8i`a7<`&D*I2t`m5{n?V40F<1zSK`B@X_= player.x_start: + player.current_x -= player.step + field.small_field_canvas.delete('all') + field.large_image_canvas.delete('all') + player.current_array_x -= 1 + Fill() + Rectangle() + elif player.current_y - player.step >= player.y_start: + player.current_x = FRAME_WIDTH - player.step + field.small_field_canvas.delete('all') + field.large_image_canvas.delete('all') + player.current_array_x = 9 + player.current_array_y -= 1 + player.current_y -= player.step + Fill() + Rectangle() + elif event.keysym == "Up": + if player.current_y - player.step >= player.y_start: + player.current_y -= player.step + field.small_field_canvas.delete('all') + field.large_image_canvas.delete('all') + player.current_array_y -= 1 + Fill() + Rectangle() + elif event.keysym == "Down": + if player.current_y + player.step < FRAME_HEIGHT: + player.current_y += player.step + field.small_field_canvas.delete('all') + field.large_image_canvas.delete('all') + player.current_array_y += 1 + Fill() + Rectangle() + + +def ImagesInArray(directory, array): + # Filling array from directory + row = column = 0 + for file in os.listdir(directory): + image_name = file + image_path = f"{directory}/{image_name}" + if directory == "../files/large_images": + image = PhotoImage(master=field.large_image_canvas, file=image_path) + else: + image = PhotoImage(master=field.small_field_canvas, file=image_path) + + array[row][column] = image + column += 1 + if column == 10: + column = 0 + row += 1 + + +def CellDesignation(array, color): + for element in array: + if element[0] == 0: + element[0] = player.current_x + element[1] = player.current_y + element[2] = color + break + + +def Action(event): + if event.keysym in ["Right", "Left", "Up", "Down"]: + Moving(event) + elif event.keysym in ["1", "2"]: + if event.keysym == "1": + CellDesignation(field.state_of_cell_array, "red") + else: + CellDesignation(field.state_of_cell_array, "green") + + +def main(): + # Creating the main window of an application + win_size = f'{WINDOW_X}x{WINDOW_Y}' + # global win + # win = Tk() + field.win.title("Sapper") + field.win.configure(bg='gray') + field.win.geometry(win_size) + + # Filling image arrays + large_directory = "../../files/large_images" + ImagesInArray(large_directory, field.large_image_array) + small_directory = "../../files/small_images" + ImagesInArray(small_directory, field.small_image_array) + + # Filling window with images + Fill() + # Drawing rectangle (player) + Rectangle() + # Binding keyboard press to function + field.win.bind("", Action) + # Starting mainloop for window + field.win.mainloop() + + +if __name__ == '__main__': + main() diff --git a/bin/__init__.py b/bin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bin/__pycache__/__init__.cpython-37.pyc b/bin/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..519283b12981c8a512bad202927d47d67d3beef4 GIT binary patch literal 120 zcmZ?b<>g`kg3gPH2_X70h=2h`Aj1KOi&=m~3PUi1CZpd70>R tlp9l=SWu8!6qA&h7ZV?!nU`4-AFo$Xd5gm)H$SB`C)Ez5^)nDN007OY8SMZ7 literal 0 HcmV?d00001 diff --git a/bin/__pycache__/main.cpython-37.pyc b/bin/__pycache__/main.cpython-37.pyc deleted file mode 100644 index ff1d4c3b2f5ce66940941429db919333b069200d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3251 zcmcguPjef$6$f^)%Oyopq)gdT9LI9p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PgCqMRo07%iXL$n`(jQTCXKuP$2;WD*>%>sb-Dy_W+Vw@MU$!*F< z4c$p}d}*|kKb9zBlSBB#DPe{k$>-EhK=yAgFRxIB$yTN^cD7E-+0>R0jTZu7PYwl+5Jf4vocd(QpI1kVP;G=3eY#>d-5qIP&X(P?ag zPCV$vT8(Tj&LN`otcpaIh}hb7i#W>Ac%Ue%EjCfkJoskq@p`zmasSyPQ_ee&);AtL zdS=8hYQMB4%=q{6huFuYgA%6k@StnQwnC~;N#G{Ej+xD`d7esbax=5}E#FJ2zL?@S zNVh1hxPrjzOd9|3;5A-lCLljf2ZJG^Y$m^JXkRrY8VI-T;V;I55j6A|YBPFaF{kSI zyu?c$3Zd8F4VTJejR#_ZH$=%37(;VQP8l=RAL%$Kj#hoxykZJ+(AIILbBGH1Wzxsv z+PFBTve4ea3bjV$OCpbmY=D^3#^bez>*3Rl*1GzNq!uwM{>C4?=;Fq?l_=@kebq0C qdw(0tz71V-X2mIgA>(puh diff --git a/bin/main.py b/bin/main.py deleted file mode 100644 index fd804d5..0000000 --- a/bin/main.py +++ /dev/null @@ -1,228 +0,0 @@ -from doctest import master -from tkinter import * - -import os - -from PIL import Image, ImageTk - -WINDOW_X = 533 + 1200 -WINDOW_Y = 950 -FRAME_WIDTH = 533 -FRAME_HEIGHT = 533 - -# Size of small image -IMAGE_SIZE = 50 - - -class Player(object): - def __init__(self): - self.x_start = 3 - self.y_start = 3 - self.current_x = self.x_start - self.current_y = self.y_start - self.step = IMAGE_SIZE + self.x_start - self.current_array_x = 0 - self.current_array_y = 0 - - def Moving(self, event): - # Moving - if event.keysym == "Right": - if self.current_x + self.step < FRAME_WIDTH: - self.current_x += self.step - field_canvas.delete('all') - large_image_canvas.delete('all') - self.current_array_x += 1 - field.Fill() - self.Rectangle() - elif self.current_y + self.step < FRAME_HEIGHT: - self.current_x = self.x_start - field_canvas.delete('all') - large_image_canvas.delete('all') - self.current_array_x = 0 - self.current_array_y += 1 - self.current_y += self.step - field.Fill() - self.Rectangle() - elif event.keysym == "Left": - if self.current_x - self.step >= self.x_start: - self.current_x -= self.step - field_canvas.delete('all') - large_image_canvas.delete('all') - self.current_array_x -= 1 - field.Fill() - self.Rectangle() - elif self.current_y - self.step >= self.y_start: - self.current_x = FRAME_WIDTH - self.step - field_canvas.delete('all') - large_image_canvas.delete('all') - self.current_array_x = 9 - self.current_array_y -= 1 - self.current_y -= self.step - field.Fill() - self.Rectangle() - elif event.keysym == "Up": - if self.current_y - self.step >= self.y_start: - self.current_y -= self.step - field_canvas.delete('all') - large_image_canvas.delete('all') - self.current_array_y -= 1 - field.Fill() - self.Rectangle() - elif event.keysym == "Down": - if self.current_y + self.step < FRAME_HEIGHT: - self.current_y += self.step - field_canvas.delete('all') - large_image_canvas.delete('all') - self.current_array_y += 1 - field.Fill() - self.Rectangle() - - # Drawing rectangle - def Rectangle(self): - field_canvas.create_rectangle(self.current_x, self.current_y, self.current_x + self.step - 2, - self.current_y + self.step - 2, width=3, outline='blue2') - - -def DrawingLargeImage(): - large_img_name = large_image_array[player.current_array_y][player.current_array_x] - - large_image_canvas.image = large_img_name - large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name) - - -class Field(object): - def __init__(self): - self.width = 533 - self.height = 533 - self.image_size = 50 - self.rows = 10 - self.columns = 10 - self.x_start = 3 - self.y_start = 3 - - # Putting images - def Fill(self): - x = self.x_start - y = self.y_start - - row = 0 - column = 0 - - # Drawing small images - for i in range(self.columns): - for j in range(self.rows): - small_image_name = small_image_array[column][row] - - field_canvas.image = small_image_name - field_canvas.create_image(x, y, anchor=NW, image=small_image_name) - - x += self.image_size + self.x_start - row += 1 - y += self.image_size + self.y_start - x = self.x_start - column += 1 - row = 0 - - # Drawing red/green rectangles - for el in state_of_cell_array: - if el[0] != 0: - field_canvas.create_rectangle(el[0], el[1], el[0] + player.step - 2, - el[1] + player.step - 2, width=3, outline=el[2]) - - DrawingLargeImage() - - -def ImagesInArray(directory, array): - # Filling array from directory - row = column = 0 - for file in os.listdir(directory): - image_name = file - image_path = f"{directory}/{image_name}" - image = PhotoImage(file=image_path) - - array[row][column] = image - column += 1 - if column == 10: - column = 0 - row += 1 - - -def CellDesignation(array, color): - for element in array: - if element[0] == 0: - element[0] = player.current_x - element[1] = player.current_y - element[2] = color - break - - -def Action(event): - global state_of_cell_array - - if event.keysym in ["Right", "Left", "Up", "Down"]: - player.Moving(event) - elif event.keysym in ["1", "2"]: - if event.keysym == "1": - CellDesignation(state_of_cell_array, "red") - else: - CellDesignation(state_of_cell_array, "green") - - -def main(): - # Creating the main window of an application - window_size = f'{WINDOW_X}x{WINDOW_Y}' - global window - window = Tk() - window.title("Sapper") - window.configure(bg='gray') - window.geometry(window_size) - - global state_of_cell_array - state_of_cell_array = [[0 for i in range(3)] for j in range(200)] - - # Creating objects - global player - global field - field = Field() - player = Player() - - # Creating arrays with names of images - global large_image_array - global small_image_array - small_image_array = [[0 for i in range(field.rows)] for j in range(field.columns)] - large_image_array = [[0 for i in range(field.rows)] for j in range(field.columns)] - - # Filling image arrays - global large_directory - global small_directory - large_directory = "../files/large_images" - ImagesInArray(large_directory, large_image_array) - small_directory = "../files/small_images" - ImagesInArray(small_directory, small_image_array) - - # Creating the frames - main_frame = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=0) - main_frame.pack(anchor=NW) - - # Creating the canvas - global field_canvas - field_canvas = Canvas(main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, highlightthickness=0, bg='light gray') - field_canvas.pack() - - # Creating the canvas for large image - global large_image_canvas - large_image_canvas = Canvas(window, width=WINDOW_X - 533 - 20, height=900, highlightthickness=0, bg='gray') - large_image_canvas.place(x=FRAME_WIDTH + 5, y=player.y_start) - - # Filling window with images - Field.Fill(field) - # Drawing rectangle (player) - Player.Rectangle(player) - # Binding keyboard press to function - window.bind("", Action) - # Starting mainloop for window - window.mainloop() - - -if __name__ == '__main__': - main()