Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit e2046e0

Browse files
Merge pull request #412 from Ratna2/deep-fine
ratna2
2 parents f7e2b45 + 8cfb44e commit e2046e0

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

  • projects/GUI based image display and transfer in python
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import tkinter as tk
2+
from tkinter import filedialog
3+
from PIL import Image, ImageTk
4+
import shutil
5+
6+
# Function to open an image using file dialog
7+
def open_image():
8+
file_path = filedialog.askopenfilename()
9+
if file_path:
10+
image = Image.open(file_path)
11+
photo = ImageTk.PhotoImage(image)
12+
label.config(image=photo)
13+
label.image = photo
14+
global current_image_path
15+
current_image_path = file_path
16+
17+
# Function to save the current image to a new location
18+
def save_image():
19+
if current_image_path:
20+
destination_path = filedialog.asksaveasfilename(defaultextension=".png")
21+
if destination_path:
22+
shutil.copy(current_image_path, destination_path)
23+
24+
# Create the main window
25+
root = tk.Tk()
26+
root.title("Image Viewer and Transfer")
27+
28+
# Create a label for displaying images
29+
label = tk.Label(root)
30+
label.pack()
31+
32+
# Create "Open" and "Save As" buttons
33+
open_button = tk.Button(root, text="Open Image", command=open_image)
34+
save_button = tk.Button(root, text="Save Image", command=save_image)
35+
open_button.pack()
36+
save_button.pack()
37+
38+
current_image_path = None
39+
40+
root.mainloop()

0 commit comments

Comments
 (0)