import tkinter as tk from tkinter import Menu, filedialog, font usedname = None def new_file(): global usedname textbox.delete('1.0', tk.END) usedname = None print('New file created') def save_file(): global usedname text = textbox.get("1.0", tk.END) if usedname: with open(usedname, "w") as file: file.write(text) print('Saved file as ' + str(usedname)) else: file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt"), ("All files", "*.*")]) if file_path: with open(file_path, "w") as file: file.write(text) print('Saved file as ' + str(file_path)) usedname = file_path def quicksave(): global usedname if usedname: text = textbox.get("1.0", tk.END) with open(usedname, "w") as file: file.write(text) print('Quicksaved file as ' + str(usedname)) else: save_file() def load_file(): global usedname file_path = filedialog.askopenfilename(filetypes=[("Text files", "*.txt"), ("All files", "*.*")]) if file_path: with open(file_path, "r") as file: text = file.read() textbox.delete("1.0", tk.END) textbox.insert(tk.END, text) usedname = file_path print('Loaded file ' + str(file_path)) def update_font(event=None): new_font_family = fontbox.get("1.0", tk.END).strip() new_font_size = int(fontsbox.get("1.0", tk.END).strip()) custom_font.config(family=new_font_family, size=new_font_size) textbox.configure(font=custom_font) fontbox.config(height=1, font=("Maiandra GD", new_font_size)) fontsbox.config(height=1, font=("Maiandra GD", new_font_size)) textbox.place(x=0, y=new_font_size * 1.5 + 10, relwidth=1, relheight=1, anchor='nw') root = tk.Tk() root.title("Editript") root.geometry("480x360") menu_bar = Menu(root) root.config(menu=menu_bar) fontbox = tk.Text(root, height=1, font="Maiandra 20") fontbox.tag_config("colored", foreground="blue", background="yellow") fontbox.place(x=0, y=0, width=300) fontbox.insert(tk.END, "Maiandra GD") fontbox.bind("<KeyRelease>", update_font) fontsbox = tk.Text(root, height=1, font="Maiandra 20") fontsbox.tag_config("colored", foreground="blue", background="yellow") fontsbox.place(x=305, y=0, width=100) fontsbox.insert(tk.END, "20") fontsbox.bind("<KeyRelease>", update_font) custom_font = font.Font(family=fontbox.get("1.0", tk.END).strip(), size=10) textbox = tk.Text(root, font=custom_font) textbox.tag_config("colored", foreground="blue", background="yellow") textbox.place(x=0, y=40, relwidth=1, relheight=1, anchor='nw') update_font() file_menu = Menu(menu_bar, tearoff=0) menu_bar.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="New", command=new_file) file_menu.add_command(label="Save", command=quicksave) file_menu.add_command(label="Save As", command=save_file) file_menu.add_command(label="Open", command=load_file) file_menu.add_separator() file_menu.add_command(label="Quit Editript", command=root.quit) print('Successfully started Editript 1 (Python 3.4+)') print('Do not close this window') root.mainloop() print('Successfully shut down Editript 1 (Python 3.4+)')
Tested mainly with Python 3.11 in Jetbrains's PyCharm 2.1.2024. Confirmed compatibility with: Python 3.12: v3-4 Python 3.11: v1-4 Python 3.10: v1-2 Python 3.9: v1 Python 3.8: unknown Python 3.7: v2, v4 Python 3.6: unknown Python 3.5: unknown Python 3.4: unknown Please contribute to this section with info for compatibility with the current version. Testers: @ST36_Programmer, @EverSwirl, @Bob_the_best_banana, @ThatCat2000 Changelog: v4: support for font size modification added. v3: added fonts. modifying the textbox above the actual text box will change the font. this is not yet saved. v2: fixed a bug where the editor would crash when attempting to quicksave a file before properly saving at least twice. v1: initial release