- Tkinter modülünü içe aktarın.
- Bir ana pencere oluşturun ve etiketleri, metin kutularını ve diğer gerekli bileşenleri ekleyin.
- Dosya açma, kaydetme ve yeni dosya oluşturma işlevlerini eklemek için düğmeler ekleyin.
- Dosyaları okumak ve yazmak için Python dosya işlemlerini kullanın.
- Uygulamayı çalıştırın ve test edin.
from tkinter import *
from tkinter.filedialog import askopenfilename, asksaveasfilename
def new_file():
text.delete("1.0", END)
window.title("Untitled")
def open_file():
filepath = askopenfilename(defaultextension=".txt",
filetypes=[("Text Files", "*.txt"),
("All Files", "*.*")])
if not filepath:
return
text.delete("1.0", END)
with open(filepath, "r") as file:
text.insert(END, file.read())
window.title(f"{filepath}")
def save_file():
filepath = asksaveasfilename(defaultextension=".txt",
filetypes=[("Text Files", "*.txt"),
("All Files", "*.*")])
if not filepath:
return
with open(filepath, "w") as file:
file.write(text.get("1.0", END))
window.title(f"{filepath}")
window = Tk()
window.title("Untitled")
window.geometry("800x600")
text = Text(window, font=("Helvetica", 12), padx=10, pady=10)
text.pack(expand=True, fill=BOTH)
menu_bar = Menu(window)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label="New", command=new_file)
file_menu.add_command(label="Open", command=open_file)
file_menu.add_command(label="Save", command=save_file)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=window.quit)
menu_bar.add_cascade(label="File", menu=file_menu)
app_menu = Menu(menu_bar, tearoff=0)
app_menu.add_command(label="About")
menu_bar.add_cascade(label="Application", menu=app_menu)
window.config(menu=menu_bar)
window.mainloop()