Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit c6690e5

Browse files
Added some featutes and validated code
1 parent c1d2358 commit c6690e5

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
import tkinter as tk
2-
from tkinter import filedialog
3-
from tkinter import messagebox
2+
from tkinter import filedialog, messagebox
43
from PIL import Image
5-
6-
7-
root= tk.Tk()
8-
9-
canvas1 = tk.Canvas(root, width = 300, height = 250, bg = 'orange', relief = 'raised')
4+
root = tk.Tk() # Tkinter window initialized
5+
root.title('Converter') # Title of the window
6+
canvas1 = tk.Canvas(root, width=300, height=250, bg='orange', relief='raised')
107
canvas1.pack()
11-
12-
label1 = tk.Label(root, text='File Converter', bg = 'lightsteelblue2')
8+
label1 = tk.Label(root, text='File Converter', bg='lightsteelblue2') # giving a title to the screen
139
label1.config(font=('helvetica', 20))
1410
canvas1.create_window(150, 60, window=label1)
15-
root.title('Converter')
11+
im1 = None # variable to store path of image
12+
1613

17-
def getJPG ():
14+
def getJPG():
15+
'''Function to get image location and open it with pillow'''
1816
global im1
19-
2017
import_file_path = filedialog.askopenfilename()
2118
im1 = Image.open(import_file_path)
22-
23-
browseButton_JPG = tk.Button(text=" Import JPEG File ", command=getJPG, bg='royalblue', fg='white', font=('helvetica', 12, 'bold'))
19+
20+
21+
font = ('helvetica', 12, 'bold')
22+
bg = 'royalblue'
23+
fg = 'white'
24+
browseButton_JPG = tk.Button(text=" Import JPEG File ", command=getJPG, bg=bg, fg=fg, font=font) # Browse button
2425
canvas1.create_window(150, 130, window=browseButton_JPG)
2526

26-
def convertToPNG ():
27+
28+
def convertToPNG():
29+
'''Function to change file extenstion to png and save it to User's prefered location '''
2730
global im1
28-
29-
export_file_path = filedialog.asksaveasfilename(defaultextension='.png')
30-
im1.save(export_file_path)
31+
if im1 is None:
32+
tk.messagebox.showerror("Error", "No File selected")
33+
else:
34+
export_file_path = filedialog.asksaveasfilename(defaultextension='.png')
35+
im1.save(export_file_path)
3136

32-
saveAsButton_PNG = tk.Button(text='Convert JPEG to PNG', command=convertToPNG, bg='royalblue', fg='white', font=('helvetica', 12, 'bold'))
33-
canvas1.create_window(150, 180, window=saveAsButton_PNG)
3437

35-
root.mainloop()
38+
saveAsButton_PNG = tk.Button(text='Convert JPEG to PNG', command=convertToPNG, bg=bg, fg=fg, font=font) # Convert button
39+
canvas1.create_window(150, 180, window=saveAsButton_PNG)
40+
root.mainloop()
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import os
21
from PIL import Image
3-
4-
5-
dir_path = os.path.dirname(os.path.realpath(__file__))
6-
7-
im1 = Image.open('input.jpeg')
8-
9-
im1.save('output.png')
2+
im1 = Image.open('input.jpeg') # takes input image from present folder
3+
im1.save('output.png') # output image is generated the folder

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /