Advertisement
Guest User

Untitled

a guest
Dec 5th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.65 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter.scrolledtext as scrolledtext
  3. from tkinter.filedialog import askopenfilename,asksaveasfilename
  4. import os
  5. root = Tk()
  6. root.title("Notatnik")
  7. root.geometry("644x600+350+40")
  8. TextArea = scrolledtext.ScrolledText(root , font="lucida 13")
  9. TextArea.pack(expand=True,fill=BOTH)
  10. file = None
  11. MenuBar = Menu(root)
  12. root.config(menu=MenuBar)
  13. FileMenu = Menu(MenuBar , tearoff=0)
  14. EditMenu = Menu(MenuBar , tearoff=0)
  15. MenuBar.add_cascade(label="Plik",menu=FileMenu)
  16. MenuBar.add_cascade(label="Edycja",menu=EditMenu)
  17.  
  18. def Nowy():
  19.     global file
  20.     root.title("Untitled - Notepad")
  21.     TextArea.delete(1.0,END)
  22.    
  23. def Otwórz():
  24.     global file
  25.     file = askopenfilename(defaultextension =".txt",filetypes=[("Text Documents","*.txt")])
  26.     if file == "":
  27.         file = None
  28.     else:
  29.         root.title(os.path.basename(file) + " - Notepad")
  30.         f = open(file,"r")
  31.         TextArea.insert(1.0, f.read())
  32.         f.close()
  33. def Zapisz():
  34.     global file
  35.     if file == None:
  36.         file = asksaveasfilename(defaultextension =".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
  37.         if file == "":
  38.             file = None
  39.         else:
  40.             f = open(file,"w")
  41.             f.write(TextArea.get(1.0,END))
  42.             f.close()
  43.             root.title(os.path.basename(file) + " - Notepad ")
  44.     else:
  45.         f = open(file,"w")
  46.         f.write(TextArea.get(1.0,END))
  47.         f.close()
  48. def Zapisz_jako():
  49.     global file
  50.     if file == None:
  51.         file = asksaveasfilename(defaultextension =".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
  52.         if file == "":
  53.             file = None
  54.         else:
  55.             f = open(file,"w")
  56.             f.write(TextArea.get(1.0,END))
  57.             f.close()
  58.             root.title(os.path.basename(file) + " - Notepad ")
  59.     else:
  60.         f = open(file,"w")
  61.         f.write(TextArea.get(1.0,END))
  62.         f.close()
  63.  
  64. def zamknij():
  65.     root.destroy()
  66. def wytnij():
  67.     TextArea.event_generate(("<<Cut>>"))
  68. def kopiuj():
  69.     TextArea.event_generate(("<<Copy>>"))
  70. def wklej():
  71.     TextArea.event_generate(("<<Paste>>"))
  72. FileMenu.add_command(label="Nowy" , command = Nowy)
  73. FileMenu.add_command(label="Otwórz" , command = Otwórz)
  74. FileMenu.add_command(label="Zapisz" , command = Zapisz)
  75. FileMenu.add_command(label="Zapisz jako..." , command = Zapisz_jako)
  76. FileMenu.add_separator()
  77. FileMenu.add_command(label = "Zamknij" , command = zamknij)
  78. EditMenu.add_command(label = "Wytnij" , command = wytnij)
  79. EditMenu.add_command(label = "Kopiuj" , command = kopiuj)
  80. EditMenu.add_command(label = "Wklej" , command = wklej)
  81. root.mainloop()
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement