-
Notifications
You must be signed in to change notification settings - Fork 0
/
poznámkoví blok.py
106 lines (67 loc) · 3.27 KB
/
poznámkoví blok.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# python-cz
self.__root.grid_rowconfigure(0,weight=1)
self.__root.grid_columnconfigure(0,weight=1)
#add controls (widget)
self.__thisTextArea.grid(sticky=N+E+S+W)
self.__thisFileMenu.add_command(label="New",command=self.__newFile)
self.__thisFileMenu.add_command(label="Open",command=self.__openFile)
self.__thisFileMenu.add_command(label="Save",command=self.__saveFile)
self.__thisFileMenu.add_separator()
self.__thisFileMenu.add_command(label="Exit",command=self.__quitApplication)
self.__thisMenuBar.add_cascade(label="File",menu=self.__thisFileMenu)
self.__thisEditMenu.add_command(label="Cut",command=self.__cut)
self.__thisEditMenu.add_command(label="Copy",command=self.__copy)
self.__thisEditMenu.add_command(label="Paste",command=self.__paste)
self.__thisMenuBar.add_cascade(label="Edit",menu=self.__thisEditMenu)
self.__thisHelpMenu.add_command(label="About Notepad",command=self.__showAbout)
self.__thisMenuBar.add_cascade(label="Help",menu=self.__thisHelpMenu)
self.__root.config(menu=self.__thisMenuBar)
self.__thisScrollBar.pack(side=RIGHT,fill=Y)
self.__thisScrollBar.config(command=self.__thisTextArea.yview)
self.__thisTextArea.config(yscrollcommand=self.__thisScrollBar.set)
def __quitApplication(self):
self.__root.destroy()
#exit()
def __showAbout(self):
showinfo("Notepad","Created by: Ferdinand Silva (http://ferdinandsilva.com)")
def __openFile(self):
self.__file = askopenfilename(defaultextension=".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
if self.__file == "":
self.__file = None
else:
self.__root.title(os.path.basename(self.__file) + " - Notepad")
self.__thisTextArea.delete(1.0,END)
file = open(self.__file,"r")
self.__thisTextArea.insert(1.0,file.read())
file.close()
def __newFile(self):
self.__root.title("Untitled - Notepad")
self.__file = None
self.__thisTextArea.delete(1.0,END)
def __saveFile(self):
if self.__file == None:
#save as new file
self.__file = asksaveasfilename(initialfile='Untitled.txt',defaultextension=".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
if self.__file == "":
self.__file = None
else:
#try to save the file
file = open(self.__file,"w")
file.write(self.__thisTextArea.get(1.0,END))
file.close()
#change the window title
self.__root.title(os.path.basename(self.__file) + " - Notepad")
else:
file = open(self.__file,"w")
file.write(self.__thisTextArea.get(1.0,END))
file.close()
def __cut(self):
self.__thisTextArea.event_generate("<<Cut>>")
def __copy(self):
self.__thisTextArea.event_generate("<<Copy>>")
def __paste(self):
self.__thisTextArea.event_generate("<<Paste>>")
def run(self):
self.__root.mainloop()
notepad = Notepad(width=600,height=400)
notepad.run()