-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotepad.py
621 lines (531 loc) · 24.3 KB
/
notepad.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
import os
import tempfile
import textblob
import googletrans
from tkinter import *
from gtts import gTTS
from tkinter import ttk
import sounddevice as sd
from PIL import ImageTk,Image
from playsound import playsound
from tkinter import messagebox as msg
from tkinter import font , colorchooser
from tkinter.filedialog import askopenfilename ,asksaveasfilename
def new(event = ""):
global file
root.title("Untitled - Notepad")
file = None
txt_area.delete(1.0 , "end")
#Todo : main_bar tools
def bold(event=""):
txt_get = font.Font(font = txt_area["font"])
if txt_get.actual()["weight"] == "normal":
txt_area.configure(font =(clt_font_from_combo_box,clt_font_size_from_combo_box,"bold"))
elif txt_get.actual()["weight"] == "bold":
txt_area.configure(font =(clt_font_from_combo_box,clt_font_size_from_combo_box,"normal"))
def italic(event = ""):
txt_get = font.Font(font=txt_area["font"])
if txt_get.actual()["slant"] == "roman":
txt_area.configure(font =(clt_font_from_combo_box,clt_font_size_from_combo_box,"italic"))
elif txt_get.actual()["slant"] == "italic":
txt_area.configure(font=(clt_font_from_combo_box, clt_font_size_from_combo_box, "roman"))
#
def under_line(event =""):
# print(font.Font(font=txt_area["font"]).actual())
txt_get = font.Font(font=txt_area["font"])
if txt_get.actual()["underline"] == 0:
txt_area.configure(font =(clt_font_from_combo_box,clt_font_size_from_combo_box,"underline"))
elif txt_get.actual()["underline"] == 1:
txt_area.configure(font=(clt_font_from_combo_box, clt_font_size_from_combo_box, "normal"))
def chose_color(event = ""):
chose_colors = colorchooser.askcolor()
txt_area.configure(fg = chose_colors[1])
#Todo :finish
def open_file(event = ""):
global file
file = askopenfilename(defaultextension=".txt",filetypes=[("All Files", "*.*"),("Text Documents", "*.txt")])
if file == "":
file = None
else:
root.title(os.path.basename(file) + " - Notepad")
txt_area.delete(1.0, END)
f = open(file, "r")
txt_area.insert(1.0, f.read())
f.close()
def save_file(event = ""):
global file
try:
if file == None:
file = asksaveasfilename(initialfile = "Untitled file" , defaultextension = ".txt" ,
filetypes = [("All Files" , "*.*") , ("Text_Document" , "*.txt")])
if file == "":
file=None
else:
with open(file, "w") as for_read:
for_read.write(txt_area.get(1.0,END))
root.title(os.path.basename(file) + " - Notepad")
else:
with open(file, "w") as for_read:
for_read.write(txt_area.get(1.0,END))
root.title(os.path.basename(file) + " - Notepad")
except:
return
def exit(event = ""):
global file
try:
if file == None:
if file == "":
file=None
else:
if txt_area.get(1.0,END) != "\n":
result = msg.askyesnocancel("Notice", "Do you want to save this file")
if result:
file = asksaveasfilename(initialfile="Untitled file", defaultextension=".txt",
filetypes=[("All Files", "*.*"), ("Text_Document", "*.txt")])
with open(file, "w") as for_read:
for_read.write(txt_area.get(1.0,END))
root.destroy()
else:
root.destroy()
else:
root.destroy()
else:
with open(file, "w") as for_read:
for_read.write(txt_area.get(1.0,END))
root.destroy()
except:
return
def translate_now(event=""):
global language_box
global language_box1
global languageVar
global languageVar1
try:
# src_txt = language_box.get()
tgr_txt = language_box1.get()
message = txt_area.get(1.0,END)
language_key = googletrans.LANGUAGES
language_key_ = language_key.keys()
if txt_area:
words=textblob.TextBlob(message)
lan=words.detect_language()
for i,j in language.items():
if j == tgr_txt:
lang = i
words=words.translate(from_lang=lan , to=str(lang))
txt_area.delete(1.0,END)
txt_area.insert(END,words)
except EXCEPTION as e:
msg.showerror("Error!" , "You didn't select language")
def copy(event = ""):
txt_area.event_generate("<<Copy>>")
def cut(event = ""):
txt_area.event_generate("<<Cut>>")
def paste(event = ""):
txt_area.event_generate("<<Paste>>")
def help(event = ""):
msg.showinfo("About Note pad" , "Note Pad By Bong Programiz")
def status_bar_hide(event = ""):
global show_status_bar
if show_status_bar:
sbar.pack_forget()
show_status_bar = False
else:
sbar.pack(side=BOTTOM, fill=BOTH)
show_status_bar = True
def tool_bar_hide(event = ""):
global show_tool_bar
if show_tool_bar:
tool_bar.pack_forget()
show_tool_bar = False
else:
txt_area.pack_forget()
sbar.pack_forget()
tool_bar.pack(side= TOP, fill= X)
txt_area.pack(fill = BOTH , expand = True)
sbar.pack(side=BOTTOM, fill=BOTH)
show_tool_bar=True
def find_fun(event=""):
def find(event=None):
word = find_input.get()
txt_area.tag_remove("match", "1.0", END)
matches = 0
if word:
start_pos = "1.0"
while True:
start_pos = txt_area.search(word, start_pos, stopindex=END)
if not start_pos:
break
end_pos = f"{start_pos}+{len(word)}c"
txt_area.tag_add("match", start_pos, end_pos)
matches += 1
start_pos = end_pos
txt_area.tag_config("match", foreground="red", background="yellow")
elif word is False:
msg.showinfo("Find Text","No word matched")
def replace():
word = find_input.get()
replace_txt = replace_input.get()
content = txt_area.get(1.0,"end")
new_content = content.replace(word,replace_txt)
txt_area.delete(1.0,"end")
txt_area.insert(1.0,new_content)
find_window = Toplevel(root)
find_window.wm_iconbitmap("icon\\note pad.ico")
find_window.resizable(0,0)
#Todo :find frm
find_frm = ttk.LabelFrame(find_window,text = "Find and Replace word" )
find_frm.pack(pady = 20)
txt_find = ttk.Label(find_frm , text = "Find")
txt_replace = ttk.Label(find_frm , text = "Replace")
find_input = ttk.Entry(find_frm , width=30)
replace_input = ttk.Entry(find_frm , width=30)
find_input.focus()
find_btn = ttk.Button(find_frm,text = "Find" , command = find)
replace_btn = ttk.Button(find_frm,text = "Replace" , command = replace)
txt_find.grid(row = 0 ,column = 0 ,padx = 4 ,pady = 4)
txt_replace.grid(row = 1 ,column = 0 ,padx = 4 ,pady = 4)
find_input.grid(row = 0 ,column = 1 ,padx = 4 ,pady = 4)
replace_input.grid(row = 1 ,column = 1 ,padx = 4 ,pady = 4)
find_btn.grid(row = 2 ,column = 0 ,padx = 4 ,pady = 4)
replace_btn.grid(row = 2 ,column = 1 ,padx = 4 ,pady = 4)
def clear(event=""):
txt_area.delete(1.0,"end")
def txt_left_align(event=""):
str_all_txt = txt_area.get(1.0,"end")
txt_area.tag_config("left",justify = LEFT)#Todo : .tsg_config is use to change text align
txt_area.delete(1.0,END)
txt_area.insert(INSERT,str_all_txt,"left")
def change_them(*args):
color_dict = {
"Light Default": ("#000000", "#ffffff"),
"Light Plus": ("#474747", "#e0e0e0"),
"Dark": ("#c4c4c4", "#2d2d2d"),
"Red": ("#2d2d2d", "#ffe8e8"),
"Monokai": ("#d3b774", "#474747"),
"Night Blue": ("#ededed", "#6b9dc2")
}
global i
if i.get() == 1:
txt_area.config(fg = "#000000" , bg = "#ffffff")
elif i.get() == 2:
txt_area.config(fg="#474747" , bg="#e0e0e0")
elif i.get() == 3:
txt_area.config(fg="#c4c4c4" , bg="#2d2d2d")
elif i.get() == 4:
txt_area.config(fg="#2d2d2d" , bg="#ffe8e8")
elif i.get() == 5:
txt_area.config(fg="#d3b774" , bg="#474747")
elif i.get() == 6:
txt_area.config(fg="#ededed" , bg="#6b9dc2")
def txt_right_align():
str_all_txt = txt_area.get(1.0, "end")
txt_area.tag_config("right", justify=RIGHT)
txt_area.delete(1.0, END)
txt_area.insert(INSERT, str_all_txt, "right")
def txt_center_align():
str_all_txt = txt_area.get(1.0, "end")
txt_area.tag_config("center", justify=CENTER)
txt_area.delete(1.0, END)
txt_area.insert(INSERT, str_all_txt, "center")
def speaker(event = ""):
mytext = txt_area.get(1.0 , "end-1c")
words = textblob.TextBlob(mytext)
language = words.detect_language()
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save("./icon/output.mp3")
playsound('./icon/output.mp3')
os.remove("./icon/output.mp3")
def sht_cut_keys_window(event=""):
def ok():
key_window.destroy()
key_window = Toplevel(root)
key_window.title("Shortcut Keys")
key_window.wm_iconbitmap("icon\\note pad.ico")
f1 = Frame(key_window , pady = 5 , bg = "white")
f1.pack(side = BOTTOM , pady = 5)
Button(f1 , text = "Ok", command = ok , padx = 10).pack(side = BOTTOM , padx = 10)
key_window.geometry("426x298")
key_window.configure(background = "white")
key_window.focus()
key_window.resizable(0,0)
image = Image.open("icon\\short cut.png")
photo = ImageTk.PhotoImage(image)
varun_label = Label(key_window , image=photo)
varun_label.pack()
key_window.mainloop()
if __name__ == '__main__':
root = Tk()
height = 665
width = 1200
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
# print(f"{w}x{h}")
root.geometry(f"{w-200}x{h-120}")
root.minsize(705,55)
root.title("Untitled - Notepad")
root.wm_iconbitmap("icon\\note pad.ico")
root.configure(background = "white")
#Todo use srt cut
root.bind("<Control-n>", new)
root.bind("<Control-o>", open_file)
root.bind("<Control-s>", save_file)
root.bind("<Control-e>", exit)
root.bind("<Control-x>", cut)
root.bind("<Control-h>", help)
root.bind("<Control-f>", find_fun)
root.bind("<Control-j>", clear)
root.bind("<Control-d>", status_bar_hide)
root.bind("<Control-t>", tool_bar_hide)
root.bind("<Control-q>", speaker)
root.bind("<Control-r>", sht_cut_keys_window)
root.bind("<Control-b>", bold)
root.bind("<Control-i>", italic)
root.bind("<Control-u>", under_line)
root.bind("<Control-p>", chose_color)
#Todo : end srt cut
#TODO : open image
new_icon = Image.open("icon\\new.png")
open_icon = Image.open("icon\\open.png")
save_icon = Image.open("icon\\save.png")
exit_icon = Image.open("icon\\exit.png")
copy_icon = Image.open("icon\\copy.png")
cut_icon = Image.open("icon\\cut.png")
paste_icon = Image.open("icon\\paste.png")
undo_icon = Image.open("icon\\undo.png")
redo_icon = Image.open("icon\\redo.png")
find_icon = Image.open("icon\\find.png")
shtcut_keys_icon = Image.open("icon\\shtcut keys.png")
clear_icon = Image.open("icon\\clear.png")
help_icon = Image.open("icon\\help.png")
speaker_icon = Image.open("icon\\speker.png")
tool_bar_icon = Image.open("icon\\tool bar.png")
sts_bar_icon = Image.open("icon\\status bar.png")
#Todo : finish
#Todo resize image
re_sz_new_icon = new_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_open_icon = open_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_save_icon = save_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_exit_icon = exit_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_copy_icon = copy_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_cut_icon = cut_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_paste_icon = paste_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_undo_icon = undo_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_redo_icon = redo_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_help_icon = help_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_speaker_icon = speaker_icon.resize((20,20), Image.ANTIALIAS)
re_sz_find_icon = find_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_shtcut_keys_icon = shtcut_keys_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_clear_icon = clear_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_tool_bar_icon = tool_bar_icon.resize((20,20) , Image.ANTIALIAS)
re_sz_sts_bar_icon = sts_bar_icon.resize((20,20) , Image.ANTIALIAS)
# Todo : finish
#Todo : str_re_pic
r_sz_new_icon = ImageTk.PhotoImage(re_sz_new_icon)
r_sz_open_icon = ImageTk.PhotoImage(re_sz_open_icon)
r_sz_save_icon = ImageTk.PhotoImage(re_sz_save_icon)
r_sz_exit_icon = ImageTk.PhotoImage(re_sz_exit_icon)
r_sz_copy_icon = ImageTk.PhotoImage(re_sz_copy_icon)
r_sz_cut_icon = ImageTk.PhotoImage(re_sz_cut_icon)
r_sz_redo_icon = ImageTk.PhotoImage(re_sz_redo_icon)
r_sz_undo_icon = ImageTk.PhotoImage(re_sz_undo_icon)
r_sz_paste_icon = ImageTk.PhotoImage(re_sz_paste_icon)
r_sz_help_icon = ImageTk.PhotoImage(re_sz_help_icon)
r_sz_shtcut_keys_icon = ImageTk.PhotoImage(re_sz_shtcut_keys_icon)
r_sz_speaker = ImageTk.PhotoImage(re_sz_speaker_icon)
r_sz_find_icon = ImageTk.PhotoImage(re_sz_find_icon)
r_sz_clear_icon = ImageTk.PhotoImage(re_sz_clear_icon)
r_sz_tool_bar_icon = ImageTk.PhotoImage(re_sz_tool_bar_icon)
r_sz_sts_bar_icon = ImageTk.PhotoImage(re_sz_sts_bar_icon)
#Todo : finish str icon
#Todo : tool bar icons
bold_icon = Image.open("icon\\bold.png")
italic_icon = Image.open("icon\\iatalic.png")
left_align = Image.open("icon\\left side.png")
right_align = Image.open("icon\\right side.png")
center_align = Image.open("icon\\center text align.png")
under_line_align = Image.open("icon\\under line.png")
color_icon = Image.open("icon\\color change.png")
re_sz_bold_icon = bold_icon.resize((20, 20), Image.ANTIALIAS)
re_sz_italic_icon = italic_icon.resize((20, 20), Image.ANTIALIAS)
re_sz_left_align = left_align.resize((20, 20), Image.ANTIALIAS)
re_sz_right_align = right_align.resize((20, 20), Image.ANTIALIAS)
re_sz_center_align = center_align.resize((20, 20), Image.ANTIALIAS)
re_sz_under_line_align = under_line_align.resize((20, 20), Image.ANTIALIAS)
re_sz_color_icon = color_icon.resize((20, 20), Image.ANTIALIAS)
r_sz_bold_icon = ImageTk.PhotoImage(re_sz_bold_icon)
r_sz_italic_icon = ImageTk.PhotoImage(re_sz_italic_icon)
r_sz_right_align = ImageTk.PhotoImage(re_sz_right_align)
r_sz_left_align = ImageTk.PhotoImage(re_sz_left_align)
r_sz_center_align = ImageTk.PhotoImage(re_sz_center_align)
r_sz_under_line_align = ImageTk.PhotoImage(re_sz_under_line_align)
r_sz_color_icon = ImageTk.PhotoImage(re_sz_color_icon)
#Todo : them color
#Todo : black
black_them_icon = Image.open("icon\\black circle.png")
re_sz_black_them_icon = black_them_icon.resize((20, 20), Image.ANTIALIAS)
r_sz_black_them_icon = ImageTk.PhotoImage(re_sz_black_them_icon)
light_default_icon = Image.open("icon\\light defaul.png")
re_sz_light_default_icon = black_them_icon.resize((20, 20), Image.ANTIALIAS)
r_sz_light_default_icon = ImageTk.PhotoImage(re_sz_light_default_icon)
#Todo : finish
#TODO : file menu
main_menu = Menu(root)
#Todo : file
sub_menu = Menu(main_menu , tearoff = 0)
sub_menu.add_command(label = "New" , image = r_sz_new_icon, compound = LEFT,accelerator ="Ctrl+N",command = new)
sub_menu.add_command(label = "Open", image = r_sz_open_icon, compound = LEFT,accelerator ="Ctrl+O", command = open_file)
sub_menu.add_command(label = "Save" , image = r_sz_save_icon , compound = LEFT , accelerator = "Ctrl+S" ,command = save_file)
sub_menu.add_separator()
sub_menu.add_command(label = "Exit" , image = r_sz_exit_icon , compound = LEFT , accelerator = "Ctrl+E" , command = exit)
main_menu.add_cascade(label = "File" , menu = sub_menu)
# Todo : finish
#Todo : edit
sub_menu = Menu(main_menu, tearoff=0)
sub_menu.add_command(label="Copy" , image = r_sz_copy_icon , compound = LEFT , accelerator = "Ctrl+C" , command = copy)
sub_menu.add_command(label="Cut" , image = r_sz_cut_icon , compound = LEFT , accelerator = "Ctrl+X" , command = cut)
sub_menu.add_command(label="Paste" , image = r_sz_paste_icon , compound = LEFT , accelerator = "Ctrl+V" , command = paste)
sub_menu.add_separator()
sub_menu.add_command(label="Find" , image = r_sz_find_icon , compound = LEFT , accelerator = "Ctrl+F" , command = find_fun)
sub_menu.add_command(label="Clear" , image = r_sz_clear_icon , compound = LEFT , accelerator = "Ctrl+J" , command = clear)
main_menu.add_cascade(label="Edit", menu=sub_menu)
# Todo : finish
# Todo : view
sub_menu = Menu(main_menu, tearoff=0)
sub_menu.add_checkbutton(label="Tool bar", onvalue = True , offvalue = False , variable = tool_bar_hide ,
image=r_sz_tool_bar_icon, compound=LEFT, accelerator="Ctrl+T", command=tool_bar_hide)
sub_menu.add_checkbutton(label="Status bar", onvalue = True , offvalue = False , variable = tool_bar_hide ,
image=r_sz_sts_bar_icon, compound=LEFT, accelerator="Ctrl+D" , command =status_bar_hide)
sub_menu.add_separator()
sub_menu.add_command(label="Shortcut keys", image=r_sz_shtcut_keys_icon, compound=LEFT, accelerator="Ctrl+R" ,
command = sht_cut_keys_window)
main_menu.add_cascade(label="Vew", menu=sub_menu)
# Todo : finish
# Todo : help
sub_menu = Menu(main_menu, tearoff=0)
sub_menu.add_command(label="About Note pad" , image = r_sz_help_icon ,
compound = LEFT , accelerator = "Ctrl+H" , command = help)
main_menu.add_cascade(label="Help", menu=sub_menu)
# Todo : finish
theme_color_choose = StringVar()
# Todo : Theme
sub_menu = Menu(main_menu, tearoff=0)
# re_sz them color
black_color = Image.open("icon\\black color.png")
re_sz_black_color = black_color.resize((20,20),Image.ANTIALIAS)
r_sz_black_color = ImageTk.PhotoImage(re_sz_black_color)
light_color = Image.open("icon\\light color.png")
re_sz_light_color = light_color.resize((20, 20), Image.ANTIALIAS)
r_sz_light_color = ImageTk.PhotoImage(re_sz_light_color)
# for i in color_dict:
i = IntVar()
Light_Default = sub_menu.add_radiobutton(label="Light Default", command=change_them, value=1, variable=i)
Light_Plus = sub_menu.add_radiobutton(label="Light Plus", command=change_them, value=2, variable=i)
Dark = sub_menu.add_radiobutton(label="Dark",command=change_them, value=3, variable=i)
Red = sub_menu.add_radiobutton(label="Red",command=change_them, value=4, variable=i)
Monokai = sub_menu.add_radiobutton(label="Monokai",command=change_them, value=5, variable=i)
Night_Blue = sub_menu.add_radiobutton(label="Night Blue",command=change_them, value=6, variable=i)
# color+=1
main_menu.add_cascade(label="Theme", menu=sub_menu)
# Todo : finish
root.config(menu=main_menu)
#TODO : file menu finish
#Todo : hdr_tools
tool_bar = Label(root , bg = "light grey")
tool_bar.pack(fill = X , side = TOP)
#Todo : fonts
fonts = font.families()
font_str = StringVar()
font_box = ttk.Combobox(tool_bar , width = 30 , textvar = font_str,state = "readonly")
font_box["values"] = fonts
font_box.current(fonts.index("Arial"))
font_box.grid(row = 0 , column = 0 , padx = 7)
#Todo : finish
# Todo : font size
font_size_str = IntVar()
font_size_box = ttk.Combobox(tool_bar, width=20, textvar=font_size_str, state="readonly")
font_size_box["values"] = tuple(range(4,100,2))
font_size_box.current(6)
font_size_box.grid(row=0, column=1, padx=7)
# Todo : finish
clt_font_from_combo_box = "Arial"
clt_font_size_from_combo_box = 16
# Todo : set font and font size
def set_fonts(root):
global clt_font_from_combo_box
clt_font_from_combo_box = font_str.get()
txt_area.config(font=(clt_font_from_combo_box,clt_font_size_from_combo_box))
font_box.bind("<<ComboboxSelected>>",set_fonts)
def font_size(root):
global clt_font_size_from_combo_box
clt_font_size_from_combo_box = font_size_str.get()
txt_area.config(font = (clt_font_from_combo_box,clt_font_size_from_combo_box))
font_size_box.bind("<<ComboboxSelected>>" , font_size)
# Todo : finish
#Todo : tools bar button
btn = ttk.Button(tool_bar , image = r_sz_bold_icon , command = bold)
btn.grid(row = 0 , column = 2, padx = 5)
btn1 = ttk.Button(tool_bar, image=r_sz_italic_icon , command = italic)
btn1.grid(row=0, column=3 , padx = 5)
btn2 = ttk.Button(tool_bar , image = r_sz_under_line_align , command = under_line)
btn2.grid(row = 0 , column = 4 , padx = 5)
btn3 = ttk.Button(tool_bar , image = r_sz_color_icon , command = chose_color)
btn3.grid(row = 0 , column = 5 , padx = 5)
btn4 = ttk.Button(tool_bar , image = r_sz_right_align , command = txt_left_align)
btn4.grid(row = 0 , column = 6 , padx = 5)
btn5 = ttk.Button(tool_bar , image = r_sz_center_align , command = txt_center_align)
btn5.grid(row = 0 , column = 7 , padx = 5)
btn6 = ttk.Button(tool_bar, image=r_sz_left_align, command = txt_right_align)
btn6.grid(row=0, column=8, padx=5)
btn7 = ttk.Button(tool_bar, image=r_sz_speaker , command = speaker)
btn7.grid(row=0, column=9, padx=5)
#Todo : finish
#Todo : for google translate
language = googletrans.LANGUAGES
languageVar = list(language.values())
language_box = ttk.Combobox(tool_bar , values = languageVar , state = "r" , font = "lucida 10")
language_box.grid(row=0, column=10, padx=5)
language_box.set("english")
lan_btn_pic = Image.open("icon\\translate.png")
re_sz_lan_btn_pic = lan_btn_pic.resize((20,20) , Image.ANTIALIAS)
r_sz_lan_btn_pic = ImageTk.PhotoImage(re_sz_lan_btn_pic)
lan_btn = Button(tool_bar,image = r_sz_lan_btn_pic , command = translate_now).grid(row = 0 , column =11 , padx = 5)
language1 = googletrans.LANGUAGES
languageVar1 = list(language.values())
language_box1 = ttk.Combobox(tool_bar, values=languageVar1, state="r", font="lucida 10")
language_box1.grid(row=0, column=12, padx=5)
language_box1.set("bengali")
#TODO : crt scroll bar
scrl_bar = Scrollbar(root)
scrl_bar.pack(side = RIGHT , fill = Y)
#TODO : finish
#TODO : crt text area
txt_area = Text(root , yscrollcommand = scrl_bar.set, font = "arial 16", undo = True)# bg= f"{bg}" , fg = f"{fg}"
txt_area.pack(fill = BOTH, expand = True)
scrl_bar.config(command = txt_area.yview)
txt_area.focus_set()
file = None
# TODO: finish txt area
#TODO: crt sts bar
show_status_bar = BooleanVar()
show_status_bar.set(True)
show_tool_bar = BooleanVar()
show_tool_bar.set(True)
sbar = Label(root, text = "Status Bar" , relief=SUNKEN, anchor=CENTER, padx=8, font=('lucida 9'))
sbar.pack(side=BOTTOM, fill=BOTH)
text_cng = False
def show_chr_and_word(event=None):
if txt_area.edit_modified():
global text_cng
text_cng = True
words = len(txt_area.get(1.0, 'end-1c').split())
characters = len(txt_area.get(1.0, 'end-1c').replace(" ",""))
count = 0
for space in str(characters):
if space.isspace() == True:
count += 1
sbar.config(text=f"Characters: {characters} words: {words} spaces: {count}")
txt_area.edit_modified(False)
txt_area.bind("<<Modified>>" , show_chr_and_word)
# TODO : finish sts bar
root.mainloop()