forked from kartikeysingh6/kartik_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage_Converter.py
More file actions
48 lines (35 loc) · 1.71 KB
/
Image_Converter.py
File metadata and controls
48 lines (35 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
from PIL import Image
root= tk.Tk()
canvas1 = tk.Canvas(root, width = 300, height = 320, bg = 'lightsteelblue2', relief = 'raised')
canvas1.pack()
label1 = tk.Label(root, text='File Conversion Tool', bg = 'lightsteelblue2')
label1.config(font=('helvetica', 20))
canvas1.create_window(150, 60, window=label1)
def getJPG():
global im1
import_file_path = filedialog.askopenfilename()
im1 = Image.open(import_file_path)
def getPNG():
global im2
import_file_path = filedialog.askopenfilename()
im2 = Image.open(import_file_path)
browseButton_JPG = tk.Button(text=" Import JPG File ", command=getJPG, bg='royalblue', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 130, window=browseButton_JPG)
browseButton_PNG = tk.Button(text=" Import PNG File ", command=getJPG, bg='royalblue', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 180, window=browseButton_PNG)
def convertToPNG():
global im1
export_file_path = filedialog.asksaveasfilename(defaultextension='.png')
im1.save(export_file_path)
def convertToJPG():
global im2
export_file_path = filedialog.asksaveasfilename(defaultextension='.jpg')
im2.save(export_file_path)
saveAsButton_PNG = tk.Button(text='Convert JPG to PNG', command=convertToPNG, bg='royalblue', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 230, window=saveAsButton_PNG)
saveAsButton_JPG = tk.Button(text='Convert PNG to JPG', command=convertToJPG, bg='royalblue', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 280, window=saveAsButton_JPG)
root.mainloop()