-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriya1.py
More file actions
35 lines (27 loc) · 1.05 KB
/
Copy pathpriya1.py
File metadata and controls
35 lines (27 loc) · 1.05 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
import tkinter as tk
from tkinter import messagebox
import os
def rename_file():
old_name = old_filename_entry.get()
new_name = new_filename_entry.get()
try:
os.rename(old_name, new_name)
messagebox.showinfo("Success", f"File renamed from {old_name} to {new_name}")
except FileNotFoundError:
messagebox.showerror("Error", f"File {old_name} not found.")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {e}")
# Set up the main window
root = tk.Tk()
root.title("File Renamer")
# Create and place labels, entries, and buttons
tk.Label(root, text="Old Filename:").grid(row=0, column=0)
tk.Label(root, text="New Filename:").grid(row=1, column=0)
old_filename_entry = tk.Entry(root)
old_filename_entry.grid(row=0, column=1)
new_filename_entry = tk.Entry(root)
new_filename_entry.grid(row=1, column=1)
rename_button = tk.Button(root, text="Rename File", command=rename_file)
rename_button.grid(row=2, columnspan=2)
# Start the Tkinter event loop
root.mainloop()