Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import tkinter.scrolledtext as scrolledtext
- from tkinter.filedialog import askopenfilename,asksaveasfilename
- import os
- root = Tk()
- root.title("Notatnik")
- root.geometry("644x600+350+40")
- TextArea = scrolledtext.ScrolledText(root , font="lucida 13")
- TextArea.pack(expand=True,fill=BOTH)
- file = None
- MenuBar = Menu(root)
- root.config(menu=MenuBar)
- FileMenu = Menu(MenuBar , tearoff=0)
- EditMenu = Menu(MenuBar , tearoff=0)
- MenuBar.add_cascade(label="Plik",menu=FileMenu)
- MenuBar.add_cascade(label="Edycja",menu=EditMenu)
- def Nowy():
- global file
- root.title("Untitled - Notepad")
- TextArea.delete(1.0,END)
- def Otwórz():
- global file
- file = askopenfilename(defaultextension =".txt",filetypes=[("Text Documents","*.txt")])
- if file == "":
- file = None
- else:
- root.title(os.path.basename(file) + " - Notepad")
- f = open(file,"r")
- TextArea.insert(1.0, f.read())
- f.close()
- def Zapisz():
- global file
- if file == None:
- file = asksaveasfilename(defaultextension =".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
- if file == "":
- file = None
- else:
- f = open(file,"w")
- f.write(TextArea.get(1.0,END))
- f.close()
- root.title(os.path.basename(file) + " - Notepad ")
- else:
- f = open(file,"w")
- f.write(TextArea.get(1.0,END))
- f.close()
- def Zapisz_jako():
- global file
- if file == None:
- file = asksaveasfilename(defaultextension =".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
- if file == "":
- file = None
- else:
- f = open(file,"w")
- f.write(TextArea.get(1.0,END))
- f.close()
- root.title(os.path.basename(file) + " - Notepad ")
- else:
- f = open(file,"w")
- f.write(TextArea.get(1.0,END))
- f.close()
- def zamknij():
- root.destroy()
- def wytnij():
- TextArea.event_generate(("<<Cut>>"))
- def kopiuj():
- TextArea.event_generate(("<<Copy>>"))
- def wklej():
- TextArea.event_generate(("<<Paste>>"))
- FileMenu.add_command(label="Nowy" , command = Nowy)
- FileMenu.add_command(label="Otwórz" , command = Otwórz)
- FileMenu.add_command(label="Zapisz" , command = Zapisz)
- FileMenu.add_command(label="Zapisz jako..." , command = Zapisz_jako)
- FileMenu.add_separator()
- FileMenu.add_command(label = "Zamknij" , command = zamknij)
- EditMenu.add_command(label = "Wytnij" , command = wytnij)
- EditMenu.add_command(label = "Kopiuj" , command = kopiuj)
- EditMenu.add_command(label = "Wklej" , command = wklej)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement