| Home | Code/Games | About me |
|---|
a python program that is alot like the windows notepad but has dark mode (ctrl + [ = dark mode, ctrl + ] = light mode)
download
The code:
from tkinter import *
from tkinter.filedialog import askopenfile
import sys, os
root = Tk()
root_width = 300
root_height = 500
monitor_width = root.winfo_screenwidth()
monitor_height = root.winfo_screenheight()
center_x = int(monitor_width /2 - root_width /2)
center_y = int(monitor_height /2 - root_height /2)
root.geometry(f'{root_width}x{root_height}+{center_x}+{center_y}')
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
root.title("text editor")
root.iconbitmap(resource_path("notepad_icon.ico"))
root.config(bg='black')
root.bind('', lambda x: sys.exit())
def open_f():
global file, entry
file = askopenfile(title="open a text file", mode="r",filetypes=(("txt files", "*.txt"), ("all files", "*.*")))
content = file.read()
file.close()
my_button.destroy()
entry = Text(root, width=root.winfo_width(), height=root.winfo_height())
entry.configure(bg= 'black', fg='white', insertbackground='white')
entry.pack()
entry.insert(END, content)
root.bind('', lambda x: abcde())
def abcde():
save_file = open(file.name, "w")
text = entry.get(1.0, END)[:-1]
save_file.write(text)
def theme1():
entry.configure(bg= 'black', fg='white', insertbackground='white')
root.bind('', lambda x: theme1())
def theme2():
entry.configure(bg= 'white', fg='black', insertbackground='white')
root.bind('', lambda x: theme2())
my_button = Button(root, text="Open File", command=open_f, bg="#00ebeb", fg="black")
my_button.pack(expand=True)
root.mainloop()