This repository was archived by the owner on Apr 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
projects/GUI based image display and transfer in python Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments