44
55import sys
66import webbrowser
7- from tkinter import Tk , Menu , messagebox , Canvas , Label , Entry , Button
7+ from tkinter import Tk , Menu , Toplevel , messagebox , Canvas , Label , Entry , Button
88from loguru import logger
99from PIL import Image , ImageTk
1010
@@ -58,7 +58,7 @@ def show_version():
5858 """ This function shows the version of the project. """
5959
6060 logger .info ('Function show_version was initialized.' )
61- messagebox .showinfo ('Version' , 'Version 0.4.1 ' )
61+ messagebox .showinfo ('Version' , 'Version 0.5.0 ' )
6262 logger .info ('Function show_version was closed.' )
6363
6464
@@ -110,13 +110,30 @@ def resize_image():
110110 def resizing ():
111111 """This function will resize images."""
112112
113+ global root
114+
113115 logger .info ('Function resize_image and resizing was closed.' )
114116 logger .info (
115117 f"""
116118 x_entry_resizing_window - { x_entry_resizing_window .get ()}
117119 y_entry_resizing_window - { y_entry_resizing_window .get ()} """ )
118120
119- # TODO: There should be a function text here that resizes the image.
121+ resize = int (x_entry_resizing_window .get ()), int (
122+ y_entry_resizing_window .get ())
123+
124+ resized_img = image_pil .resize (resize )
125+ resized_img .save ('resized_image.png' )
126+
127+ reimage_pil = Image .open ('resized_image.png' )
128+ (width , height ) = reimage_pil .size
129+ reimage = ImageTk .PhotoImage (reimage_pil )
130+
131+ root .destroy ()
132+
133+ root = Toplevel ()
134+ root .geometry (f'{ width } x{ height } ' )
135+
136+ main (width , height , reimage )
120137
121138 resizing_window = Tk ()
122139 resizing_window .geometry ('404x65' )
@@ -141,36 +158,43 @@ def resizing():
141158 resizing_window .mainloop ()
142159
143160
144- FILE_PATH = str (sys .argv [1 ])
161+ @logger .catch
162+ def main (width , height , image ):
145163
146- image_pil = Image . open ( FILE_PATH )
147- ( width , height ) = image_pil . size
164+ root . title ( 'Image-Viewer' )
165+ root . resizable ( False , False )
148166
149- root = Tk ()
150- root .title ('Image-Viewer' )
151- root .geometry (f'{ width } x{ height } ' )
152- root .resizable (False , False )
167+ menu = Menu (root )
168+ root .config (menu = menu )
169+
170+ about_menu = Menu (menu )
171+ edit_image_menu = Menu (menu )
172+
173+ about_menu .add_command (label = 'License' , command = show_license )
174+ about_menu .add_command (label = 'Github' , command = opening_github )
175+ about_menu .add_command (label = 'Version' , command = show_version )
176+ edit_image_menu .add_command (label = 'Crop Image' , command = crop_image )
177+ edit_image_menu .add_command (label = 'Resize Image' , command = resize_image )
153178
154- menu = Menu ( root )
155- root . config ( menu = menu )
179+ menu . add_cascade ( label = 'About' , menu = about_menu )
180+ menu . add_cascade ( label = 'Edit Image' , menu = edit_image_menu )
156181
157- about_menu = Menu (menu )
158- edit_image_menu = Menu (menu )
182+ canvas = Canvas (root , width = width , height = height )
183+ canvas .create_image (width / 2 , height / 2 , image = image )
184+ canvas .pack ()
159185
160- about_menu .add_command (label = 'License' , command = show_license )
161- about_menu .add_command (label = 'Github' , command = opening_github )
162- about_menu .add_command (label = 'Version' , command = show_version )
163- edit_image_menu .add_command (label = 'Crop Image' , command = crop_image )
164- edit_image_menu .add_command (label = 'Resize Image' , command = resize_image )
186+ logger .info ('Root window was initialized.' )
187+ root .mainloop ()
165188
166- menu .add_cascade (label = 'About' , menu = about_menu )
167- menu .add_cascade (label = 'Edit Image' , menu = edit_image_menu )
168189
169- image = ImageTk .PhotoImage (image_pil )
190+ FILE_PATH = str (sys .argv [1 ])
191+
192+ image_pil = Image .open (FILE_PATH )
193+ (width , height ) = image_pil .size
194+
195+ root = Toplevel ()
196+ root .geometry (f'{ width } x{ height } ' )
170197
171- canvas = Canvas (root , width = width , height = height )
172- canvas .create_image (width / 2 , height / 2 , image = image )
173- canvas .pack ()
198+ main_image = ImageTk .PhotoImage (image_pil )
174199
175- logger .info ('Root window was initialized.' )
176- root .mainloop ()
200+ main (width , height , main_image )
0 commit comments