-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·145 lines (122 loc) · 3.54 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# TODO: center the packed labels
# TODO: add separator between labels
from tkinter import *
from tkinter import ttk
# setting the window up
root = Tk()
scrw, scrh = root.winfo_screenwidth(), root.winfo_screenheight()
root.title('super duper unfunctonial note app')
root.geometry('500x500-{}+{}'.format(int(scrw/2-250), int(scrh/2-270)))
root.resizable(False, False)
# ---------------------
# setting images
eyeon = PhotoImage(file = 'tk_imgs/eyeon.png',)
eyeoff = PhotoImage(file = 'tk_imgs/eyeoff.png',)
# ------------
# setting background
bckgrnd = Label(text='', background='#1e1e1e')
bckgrnd.place(x=206, y=0, width=294 ,height=500)
# ------------
# gets the width of the text inside entry bar
def get_width():
label = Label(root, text=entxt.get())
label.place(x=0, y=-100)
root.update_idletasks()
width = label.winfo_width()
label.destroy()
return width
# -------------------------------------
def move_buttons(way=''):
if way == 'down':
sbutton.place(y=57)
dbutton.place(y=92)
showtxt.place(y=57)
elif way == 'up':
sbutton.place(y=35)
dbutton.place(y=70)
showtxt.place(y=35)
else:
print('move_buttons function got wrong variable')
limit = 0
ycord = 0
labels_list = []
def svtxt():
global ycord, limit
if limit < 22:
if entxt.get():
width = get_width()
label = Label(root, text=entxt.get(), bg='#1e1e1e')
if width > 285:
pass
else:
label.place(x=213, y=ycord)
labels_list.append(label)
ycord += 22
limit += 1
else:
warning.config(text='Warning: limit is reached')
move_buttons('down')
def dlttxt():
global labels_list
global ycord
global limit
'''this function has to
delete all the packed labels
'''
while len(labels_list) != 0:
cur_label = labels_list.pop()
cur_label.place_forget()
cur_label.destroy()
ycord = 0
limit = 0
warning.config(text='')
move_buttons('up')
onoff = True
def chngtxt():
global onoff
if onoff:
entry.config(show='*')
showtxt.config(image=eyeoff, text='show')
onoff = False
else:
entry.config(show='')
showtxt.config(image=eyeon, text='hide')
onoff = True
warning = Label(root, text='', fg='yellow')
warning.place(x=25, y=33)
def wrnng(var, index, mode):
width = get_width()
if width > 285:
warning.config(text='Warning: text too long')
move_buttons('down')
else:
if limit != 22:
warning.config(text='')
move_buttons('up')
else:
warning.config(text='Warning: limit is reached')
move_buttons('down')
# setting entry widget
entxt = StringVar()
entry = Entry(root, borderwidth=4, textvariable=entxt, show='')
entxt.trace('w', wrnng)
entry.place(x=0, y=0)
entry.focus()
# ------------
# setting show text button
showtxt = Button(root, command=chngtxt, pady=5, image=eyeon, text='hide', compound='top', width=40)
showtxt.place(x=150, y=35)
# ------------
# setting save text button
sbutton = Button(root, text='save text', command=svtxt)
sbutton.place(x=50, y=35)
# ------------
# setting delete text button
dbutton = Button(root, text='Delete all', command=dlttxt)
dbutton.place(x=49, y=70)
# ------------
# setting seperator widget
separator = ttk.Separator(root, orient='vertical')
separator.place(x=206, y=0, height=500)
# ------------
root.mainloop()