3
3
import os
4
4
import requests
5
5
6
+
6
7
def get_ext (url : str ) -> str | None :
7
8
exts = [".png" , ".jpeg" , ".jpg" ]
8
9
for ext in exts :
9
10
if ext in url :
10
11
return ext
11
12
return None
12
13
14
+
13
15
def download_img ():
14
16
u = url_ent .get ()
15
17
n = name_ent .get ()
@@ -27,7 +29,8 @@ def download_img():
27
29
img_path = os .path .join (f , f"{ n } { ext } " )
28
30
29
31
if os .path .isfile (img_path ):
30
- messagebox .showerror ("Error" , "A file with the same name already exists." )
32
+ messagebox .showerror (
33
+ "Error" , "A file with the same name already exists." )
31
34
return
32
35
33
36
try :
@@ -38,6 +41,7 @@ def download_img():
38
41
except Exception as e :
39
42
messagebox .showerror ("Error" , f"An error occurred: { e } " )
40
43
44
+
41
45
root = tk .Tk ()
42
46
root .title ("Image Downloader" )
43
47
root .configure (bg = "#1e1e1e" )
@@ -60,7 +64,8 @@ def download_img():
60
64
folder_ent = tk .Entry (root , width = 50 )
61
65
folder_ent .pack (pady = 5 )
62
66
63
- dl_btn = tk .Button (root , text = "Download" , command = download_img , bg = "#303030" , fg = "white" )
67
+ dl_btn = tk .Button (root , text = "Download" ,
68
+ command = download_img , bg = "#303030" , fg = "white" )
64
69
dl_btn .pack (pady = 10 )
65
70
66
71
root .mainloop ()
0 commit comments