import tkinter
from tkinter import *
from tkinter.ttk import *
from tkinter.filedialog import askopenfile
def open_file():
global file_name
inp = askopenfile(mode="r")
if inp is None:
return
file_name = inp.name
data = inp.read()
text.delete('1.0', tkinter.END)
text.insert('1.0', data)
def new_file():
global file_name
file_name= "Untitled"
text.delete('1.0', tkinter.END)
def save_file():
global data
data = text.get('1.0', tkinter.END)
out = open(file_name, 'w')
out.write(data)
out.close()
def cancel():
with open("file_name","r") as f:
text=f.read()
data=text.replace("data","text")
with open("file_name","w") as f:
f.write(data)
root = tkinter.Tk()
root.title("Notepad")
root.minsize(width=500, height=500)
root.maxsize(width=500, height=500)
text = tkinter.Text(root, width=400, height=400, wrap="word")
scrollb = Scrollbar(root, orient=VERTICAL, command=text.yview)
scrollb.pack(side="right", fill="y")
text.configure(yscrollcommand=scrollb.set)
text.pack()
menuBar = tkinter.Menu(root)
fileMenu = tkinter.Menu(menuBar)
fileMenu.add_command(label="New", command=new_file)
fileMenu.add_command(label="Open", command=open_file)
fileMenu.add_command(label="Save", command=save_file)
menuBar.add_cascade(label="File", menu=fileMenu)
menuBar.add_cascade(label="Cancel", menu=cancel)
menuBar.add_cascade(label="Exit", command=root.quit)
root.config(menu=menuBar)
root.mainloop()