1
+ from tkinter import *
2
+ from tkinter .filedialog import *
3
+ from tkinter import ttk
4
+ import tkinter .scrolledtext as tkscroll
5
+ import os
6
+
7
+ root = Tk ()
8
+ root .geometry ("1000x600" )
9
+ root .title ("Notes" )
10
+ action = None
11
+
12
+ def back (frame ):
13
+ if frame == 'show' :
14
+ show_frame .lower ()
15
+ if frame == 'display' :
16
+ display_frame .lower ()
17
+ title_var .set ('' )
18
+ body .delete (1.0 ,END )
19
+
20
+ def save ():
21
+ title_text = title_var .get ()
22
+ content = body .get (1.0 ,END )
23
+ save_file = asksaveasfilename (initialfile = f'{ title_text } .txt' , defaultextension = ".txt" , filetypes = [("All Files" ,"*.*" ), ("Text Documents" ,"*.txt" )])
24
+ try :
25
+ file = open (save_file ,"w+" )
26
+ file .writelines (content )
27
+ file .close ()
28
+ except :
29
+ pass
30
+
31
+ def show ():
32
+ global action
33
+ action = 'show'
34
+ view ()
35
+
36
+ def remove ():
37
+ global action
38
+ action = 'remove'
39
+ view ()
40
+
41
+ def view ():
42
+ tree .delete (* tree .get_children ())
43
+ files = os .listdir ()
44
+ for file in files :
45
+ if '.txt' in file :
46
+ file = file [:len (file )- 4 ]
47
+ tree .insert ('' ,END ,values = (file ))
48
+ show_frame .lift ()
49
+
50
+ def OnDoubleClick (event ):
51
+ if action == 'show' :
52
+ title = tree .set (tree .identify_row (event .y ))['0' ]
53
+ files = os .listdir ()
54
+ for file in files :
55
+ if title in file :
56
+ display (file )
57
+ if action == 'remove' :
58
+ file = tree .set (tree .identify_row (event .y ))['0' ]
59
+ os .remove (f'{ file } .txt' )
60
+ view ()
61
+
62
+ def display (file ):
63
+ f = open (file ,'r' )
64
+ content = f .read ()
65
+ dis_label .insert (1.0 ,content )
66
+ display_frame .lift ()
67
+
68
+ main_frame = Frame (root ,bg = '#C2C0BE' )
69
+ main_frame .place (relx = 0 ,rely = 0 ,relwidth = 1 ,relheight = 1 )
70
+ main_frame .lift ()
71
+ show_frame = Frame (root ,bg = '#C2C0BE' )
72
+ show_frame .place (relx = 0 ,rely = 0 ,relwidth = 1 ,relheight = 1 )
73
+ show_frame .lower ()
74
+ display_frame = Frame (root ,bg = '#C2C0BE' )
75
+ display_frame .place (relx = 0 ,rely = 0 ,relwidth = 1 ,relheight = 1 )
76
+ display_frame .lower ()
77
+ title_label = Label (main_frame ,text = "Title : " ,font = ('Calibiri' , 20 ),bg = '#BEB4AA' ,relief = RAISED ).place (relx = 0.1 ,rely = 0.05 ,relwidth = 0.1 ,relheight = 0.08 )
78
+ title_var = StringVar ()
79
+ title = Entry (main_frame ,textvariable = title_var ,font = ('Calibiri' , 20 ),relief = RAISED )
80
+ title .place (relx = 0.2 ,rely = 0.05 ,relwidth = 0.6 ,relheight = 0.08 )
81
+ body = Text (main_frame ,font = ('Calibiri' , 16 ),relief = RAISED )
82
+ body .place (relx = 0.2 ,rely = 0.2 ,relwidth = 0.6 ,relheight = 0.5 )
83
+ save_btn = Button (main_frame ,text = 'Save' ,font = ('Calibiri' , 20 ),command = lambda : save ()).place (relx = 0.4 ,rely = 0.8 ,relwidth = 0.2 ,relheight = 0.1 )
84
+ show_btn = Button (main_frame ,text = 'Show All' ,font = ('Calibiri' , 20 ),command = lambda : show ()).place (relx = 0.7 ,rely = 0.8 ,relwidth = 0.2 ,relheight = 0.1 )
85
+ style = ttk .Style ()
86
+ style .theme_use ('clam' )
87
+ style .configure ("mystyle.Treeview" , font = ('Calibri' , 14 ), rowheight = 50 )
88
+ style .configure ("mystyle.Treeview.Heading" , font = ('Calibri' , 18 ,'bold' ))
89
+ tree = ttk .Treeview (show_frame , selectmode = 'browse' , style = "mystyle.Treeview" ,show = ['headings' ])
90
+ tree ['columns' ] = ('0' )
91
+ tree .heading ("0" , text = "Title" )
92
+ tree .column ("0" , minwidth = 100 ,width = 275 )
93
+ tree .place (relx = 0.1 ,rely = 0.1 ,relwidth = 0.8 ,relheight = 0.7 )
94
+ tree .bind ("<Double-1>" , OnDoubleClick )
95
+ remove_btn = Button (main_frame ,text = 'Delete' ,font = ('Calibiri' , 20 ),command = lambda : remove ()).place (relx = 0.1 ,rely = 0.8 ,relwidth = 0.2 ,relheight = 0.1 )
96
+ dis_label = tkscroll .ScrolledText (display_frame ,font = ('Calibiri' , 20 ),bg = '#ffffff' ,relief = GROOVE )
97
+ dis_label .place (relx = 0.1 ,rely = 0.1 ,relwidth = 0.8 ,relheight = 0.7 )
98
+ bact_btn_show = Button (show_frame ,text = 'Back' ,font = ('Calibiri' , 20 ),command = lambda : back ('show' )).place (relx = 0.4 ,rely = 0.85 ,relwidth = 0.2 ,relheight = 0.1 )
99
+ bact_btn_show = Button (display_frame ,text = 'Back' ,font = ('Calibiri' , 20 ),command = lambda : back ('display' )).place (relx = 0.4 ,rely = 0.85 ,relwidth = 0.2 ,relheight = 0.1 )
100
+ root .mainloop ()
0 commit comments