-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelp_about.py
735 lines (492 loc) · 23.8 KB
/
help_about.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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#!/usr/bin/env python3
"""
This file is part of Notelocked.
Copyright (C) 2022 Leonardo A. Reichert
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
#you can see the full license at: "LICENSE" file
#https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# Contact: [email protected]
#try:
#python 3
from tkinter import Tk,Toplevel,Text,Frame,Label,Button,Radiobutton,IntVar,Menu,BitmapImage;
from tkinter.font import Font;
from tkinter.messagebox import askyesno;
from tkinter.ttk import Scrollbar;
#except ImportError:
#python 2
# from Tkinter import Tk,Toplevel,Text,Frame,Label,Button,Radiobutton,IntVar,Menu;
# from tkFont import Font;
# from tkMessageBox import askyesno;
# from ttk import Scrollbar;
from webbrowser import open_new_tab; #user can open links on browser
from platform import system; #need check if SO Mac, for button right
from re import findall;
#fix for binary versions:
#from sys import exit;
import ext_funcs;
import diagram_helper;
import help_strings; #<- large strings :,) (smile)
import tiphelper;
author = "[email protected]";
version = "0.7";
ismacos = system().lower()=="darwin";
_font_order_options = ("family","size","weight","slant","underline","overstrike");
_BITMAP_GITHUB = """#define image_width 28
#define image_height 28
static char image_bits[] = {
0xff,0xff,0xff,0x0f,0xff,0xff,0xff,0x0f,0x3f,0xfe,0xf1,0x0f,0x3f,0xfc,0xf0,
0x0f,0x3f,0x00,0xf0,0x0f,0x3f,0x00,0xf0,0x0f,0x1f,0x00,0xe0,0x0f,0x1f,0x00,
0xe0,0x0f,0x1f,0x00,0xe0,0x0f,0x0f,0x00,0xc0,0x0f,0x0f,0x00,0xc0,0x0f,0x0f,
0x00,0xc0,0x0f,0x1f,0x00,0xe0,0x0f,0x1f,0x00,0xe0,0x0f,0x3f,0x00,0xf0,0x0f,
0x7f,0x00,0xf8,0x0f,0xff,0x03,0xff,0x0f,0xff,0x03,0xff,0x0f,0x9f,0x03,0xff,
0x0f,0x3f,0x00,0xff,0x0f,0xff,0x01,0xff,0x0f,0xff,0x03,0xff,0x0f,0xff,0x03,
0xff,0x0f,0xff,0x03,0xff,0x0f,0xff,0x03,0xff,0x0f,0xff,0xff,0xff,0x0f,0xff,
0xff,0xff,0x0f,0xff,0xff,0xff,0x0f
};"""
_BITMAP_BRANCH = """#define image_width 28
#define image_height 28
static char image_bits[] = {
0xff,0xff,0xff,0x0f,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
0x0f,0x3f,0xfe,0xf1,0x0f,0x1f,0xfc,0xe0,0x0f,0x8f,0x78,0xc4,0x0f,0xcf,0x79,
0xce,0x0f,0x8f,0x78,0xc4,0x0f,0x1f,0xfc,0xe0,0x0f,0x3f,0xfe,0xf1,0x0f,0x3f,
0xff,0xf3,0x0f,0x3f,0xff,0xf3,0x0f,0x3f,0x00,0xf0,0x0f,0x3f,0x00,0xf8,0x0f,
0x3f,0xff,0xff,0x0f,0x3f,0xff,0xff,0x0f,0x3f,0xff,0xff,0x0f,0x3f,0xff,0xff,
0x0f,0x3f,0xfe,0xff,0x0f,0x1f,0xfc,0xff,0x0f,0x8f,0xf8,0xff,0x0f,0xcf,0xf9,
0xff,0x0f,0x8f,0xf8,0xff,0x0f,0x1f,0xfc,0xff,0x0f,0x3f,0xfe,0xff,0x0f,0xff,
0xff,0xff,0x0f,0xff,0xff,0xff,0x0f
};"""
###############
pattern_configtag = "(<tagconfig \"(.+)\">\n((.+ ?.+\n)+)*</tagconfig>)";
pattern_tags = "((<tag (.+?)>)(.+?)</tag>)";
class MenuCopy(Menu):
def __init__(self, master_text):
self.text = master_text;
Menu.__init__(self, master_text, tearoff=False);
self.add_command(label="Copy", command=self.cmdCopy);
if ismacos:
master_text.bind("<ButtonRelease-2>", self.postMenu, True);
else:
master_text.bind("<ButtonRelease-3>", self.postMenu, True);
self.textsel = "";
self.texttagsel = "";
def setTextTag(self, label, text):
""" text inside tag, example: http://example.com in 'example' """
self.texttagsel = text;
self.entryconfig(0, label=label);
def cmdCopy(self):
self.text.clipboard_clear();
self.text.clipboard_append( self.textsel );
def postMenu(self, event):
text = self.texttagsel; #content selection by tag
self.texttagsel = "";
self.textsel = "";
try:
#have a normal selection?
text = self.text.get("sel.first", "sel.last");
self.entryconfig(0, label="Copy");
except:
pass;
if not text:
return;
self.textsel = text;
self.entryconfig(0, state="normal");
self.post(event.x_root, event.y_root);
class DiagramsPart:
def __init__(self, textwidget):
self.diagramfile = diagram_helper.CreateHelperDiagramFile(textwidget,
bg="#FFFFA0", bgtitle="#FBFBFB", fg="black");
#...
def diagramBinds(self, name, tagname):
if name == "diagramfile":
self.diagramfile.bindOnTag(tagname);
#...
_fontnames = {}; #global fonts created
class HelpFrame(Frame, DiagramsPart):
""" Frame intern for help or about window """
def __init__(self, master, themes, messages):
Frame.__init__(self, master, bg="#AAffff"); #, width=200);
self.pack(side="top", expand=True, fill="both");
self.columnconfigure(0, weight=1);
self.frame0 = Frame(self,relief="groove",bd=2,bg="#FBFBFB",width=400,height=50);
self.frame0.grid(column=0, row=0, padx=10, pady=10, sticky="nwse");
self.rowconfigure(0, weight=20);
self.frame1 = Frame(self,width=400,height=240);
self.frame1.grid(column=0, row=1, padx=10, pady=0, sticky="nwse");
self.rowconfigure(1, weight=70);
self.frame1.rowconfigure(0, weight=1);
self.frame1.columnconfigure(0, weight=1);
self.frame1.grid_propagate(0);
self.frame2 = Frame(self, bg=self["bg"],width=400,height=25);
self.frame2.grid(column=0, row=2, padx=10, pady=5, sticky="nwse");
self.rowconfigure(2, weight=20);
##### fonts ####
try:
self.fontMark = Font(name="nameProgram", exists=True);
self.fontTextNormal = Font(name="textNormal", exists=True);
except:
#first time
self.fontMark = Font(name="nameProgram", exists=False,
family="Arial", size=28, weight="bold", slant="italic");
self.fontTextNormal = Font(name="textNormal", exists=False,
family="Verdana", size=10);
# buttons links
self.frame0.columnconfigure(0, weight=1);
self.frame0.rowconfigure((0,1), weight=1);
self.frameLinks = Frame(self.frame0, bg=self.frame0["bg"]);
self.frameLinks.grid(column=0, row=1, sticky="we");
self.bmpGithub = BitmapImage(data=_BITMAP_GITHUB,
foreground=self.frame0["bg"],background="gray60");
self.bmpBranch = BitmapImage(data=_BITMAP_BRANCH,
foreground=self.frame0["bg"],background="gray60");
self.btnGit = Button(self.frameLinks, font="textNormal", text="My Github",
fg="blue", bg=self.frame0["bg"], cursor="hand2",
image=self.bmpGithub,compound="left", relief="flat", overrelief="ridge",
command=lambda: self.askOpenSite("https://github.com/LeonardoReichert"),
);
self.btnGit.pack(side="left", padx=10);
self.btnBranch = Button(self.frameLinks, font="textNormal", text="Notelocked Github",
fg="blue", bg=self.frame0["bg"], cursor="hand2",
image=self.bmpBranch,compound="left", relief="flat", overrelief="ridge",
command=lambda: self.askOpenSite("https://github.com/LeonardoReichert/Notelocked"),
);
self.btnBranch.pack(side="left");
tip = tiphelper.TipHelper(self);
tip.putOn(self.btnGit, "Open Github link profile");
tip.putOn(self.btnBranch, "Open Github link repository");
# elements into frames
self.lbProgName = Label(self.frame0, bg=self.frame0["bg"], text="Notelocked v"+version,
font=self.fontMark);
self.lbProgName.grid(column=0, row=0, sticky="we");
# text body message
self.text = Text(self.frame1,wrap="word",font=self.fontTextNormal,
bg="#FBFBFB", tabs=35, fg="black");
self.text.grid(column=0, row=0, sticky="nsew");
try:
self.text.configure(cursor="");
self.text.configure(inactiveselectbackground=self.text["selectbackground"]);
except:
pass;
self.sby = Scrollbar(self.frame1,orient="vertical",command=self.text.yview);
self.sby.grid(column=1,row=0,sticky="ns");
self.text.configure(yscrollcommand=self.sby.set);
self.menucopy = MenuCopy(self.text);
self.ntag = 0;
##### Create Diagrams #####
DiagramsPart.__init__(self, self.text);
###########################
##### Langs #####
self.frameLangs = Frame(self.text, bg="gray90");
self.text.columnconfigure(0, weight=1); # <- need for place langs to right
self.text.grid_propagate(0); #<- need for langs frame, avoid root geometry autoexpand
try:
self.getvar("langtheme");
except:
self.setvar("langtheme", "en"); #<- default lang
###########################
self.themes = themes; #<-titles
self.msgs = list(messages);
self.selecMsg = IntVar(value=0);
index = 0;
for theme in themes:
Radiobutton(self.frame2,text=theme,command=self._selectMsg,
indicatoron=False,bd=1,value=index,variable=self.selecMsg,
).pack(side="left",padx=3);
index += 1;
self.stateCopy = Label(self.text,text="copied!",width=9,relief="solid",
font=self.fontTextNormal,bg="#FFFFAA",bd=1);
self._idEventHiddenCopy = 0;
self._selectMsg();
#self.wait_visibility();
self.focus_set();
def _selectMsg(self, msgToParse=None):
""" Called by bottoms buttons (titles, license, etc) """
if not msgToParse:
# called by normal theme button
index = self.selecMsg.get();
#theme = self.themes[index]; #name of title, theme, no needed now
msg = self.msgs[index];
#have langs ?
self.frameLangs.grid_forget(); #hidde langs frame container
if type(msg) == dict: #yes, msg is a container of diferents langs
for btnlang in self.frameLangs.winfo_children():
btnlang.destroy(); #clear old langs
def getcmdlang(selmsg):
def setlang():
self._selectMsg(selmsg);
return setlang;
for lang in msg:
msg_content = msg[lang];
Radiobutton(self.frameLangs,text=lang.title(),bd=1,fg="black",
bg="#CCCCCC",selectcolor="#CCCCCC",activebackground="#CCCCCC",
command=getcmdlang(msg_content),indicatoron=False,
variable="langtheme",value=lang).pack(side="left");
self.frameLangs.grid(row=0, column=0, sticky="ne");
#try remember last lang
lang = self.getvar("langtheme");
if not lang in msg: #<- no selected value ?
lang = next(iter(msg)); #<- first, default lang
self.setvar("langtheme", lang); #set default lang button as pressed
msg = msg[lang];
else:
# called by "button lang" on theme
msg = msgToParse;
self.parseMessage(msg);
def parseMessage(self, message):
""" Message was selected, now need parse """
msg = message;
self.text.configure(state="normal");
self.text.delete("1.0", "end");
for tagname in self.text.tag_names():
if tagname != "btncursor2": #tags forever
self.text.tag_delete(tagname);
self.tagstobind = {}; #bind tags
self.parseConfigTags( help_strings._tagsconfigdefault_ );
self.parseConfigTags(msg); #<- search configs <tagconfig>
#extract <body>
start = msg.find("<body>");
end = msg.rfind("</body>");
body = "";
if start != -1 and end > start: #re.findall i cannot find with *\n*
body = msg[start+len("<body>"):end];
self.parseBody(body);
self.parseBindTags();
self.text.tag_bind("btncursor2", "<Enter>", self._cursor2);
self.text.tag_bind("btncursor2", "<Leave>", self._cursorNormal);
self.text.configure(state="disabled");
return;
def parseBody(self, body):
""" parse text on body and create tags indexs """
tags_result = findall(pattern_tags, body);
lastend = 0; #now try extract tags and parse tags
for allstr, _starttag, tagname, inside in tags_result:
#allstr: "<tag tagname>inside</tag>"
index = body.find(allstr);
if index == -1:
continue;
body = body.replace(allstr, inside, 1);
self.text.insert("end", body[lastend:index]);
self.text.insert("end", inside, tagname);
lastend = index + len(inside);
self.text.insert("end", body[lastend:]);
def parseConfigTags(self, msg):
"""
apply configs <tagconfig>
find all config tags in msg and remove,
apply the tags config styles, create fonts .."""
#no need re-create fonts repeated:
for newconfigtag in findall(pattern_configtag, msg):
allstr, tagname, opts, _last = newconfigtag;
for opt in opts.split("\n"):
if opt == "": break; #end
line = opt.split(" ", 1);
value="";
if len(line)==2:
value = line[1];
opt = line[0];
if opt == "font":
values = value.split(",");
fontname = values[0]; #id
if not fontname in _fontnames:
#create a first time the font, no duplicate
try:
fontargs = tuple(values[1:]);
# options imported from default global Font
font = self.fontTextNormal.copy();
default = font.actual();
#keys = tuple(default); #keys names
#best compatibility in Python 3.x and 2.x (dicts order):
keys = _font_order_options;
actual = dict( zip(keys, fontargs));
#search "defaults"
for k in actual:
if actual[k].lower() == "default":
actual[k] = default[k];
#only apply Font changes mensioned and != Default
font.config(**actual);
_fontnames[fontname] = font;
except Exception as msg:
print("debug: cannot create Font", fontname, msg, values);
continue;
#fontname = "";
value = fontname;
fontobj = _fontnames[fontname];
self.text.tag_config(tagname, font=fontobj);
continue;
elif opt.startswith("-"): #binds
if not tagname in self.tagstobind:
self.tagstobind[tagname] = [];
self.tagstobind[tagname].append( (opt, value) );
continue;
elif opt.startswith("//"):
#a comment
continue;
self.text.tag_config(tagname, {opt:value});
def parseBindTags(self):
""" incoming task, apply a personalized events binds to
tags created previous """
ntagbind = 0;
for tagname in self.tagstobind:
actions = self.tagstobind[tagname];
for action, value in actions:
action = action.lower(); #lower letters
#now, value is a condition, object, etc
if action == "-binddiagram":
self.diagramBinds(value, tagname);
continue;
#more if..
#now, value is a value for user
indexranges = iter( self.text.tag_ranges(tagname) );
for iFirst in indexranges:
iLast = next(indexranges);
selvalue = value; #dont modify original, i will use on next indexs
if ";" in selvalue: # ; separator of two values
selvalue, selvalue2 = selvalue.split(";", 1);
else:
selvalue2 = ""; #i will use ""(null) or "value default"
if selvalue == ".":
#value inside, content into tag <tag name>value here</tag>
selvalue = self.text.get(iFirst, iLast);
if action == "-bindcopyable":
self.addTextWithCopyCmd(iLast, selvalue, selvalue2 or "copy");
elif action == "-bindcopybymenu":
self.bindTextCopyByMenu(iFirst,iLast,selvalue,selvalue2 or "Copy this");
elif action == "-bindopenweb":
self.bindWebOpener(iFirst, iLast, selvalue);
self.text.tag_config("btncopy", underline=True, font=self.fontTextNormal);
def bindWebOpener(self, first, last, url):
tag = "webopen%d" % self.ntag;
self.ntag+=1;
self.text.tag_add("btncursor2", first, last);
self.text.tag_add(tag, first, last);
self.text.tag_bind(tag, "<Button-1>", lambda e=None: self.askOpenSite(url));
def askOpenSite(self,url):
if askyesno(parent=self, title="Open browser",
message="Are you want open link \"%s\" in a new tab of the web browser?" % url):
open_new_tab(url);
def bindTextCopyByMenu(self, first, last, text, label):
tag = "copybymenu%d" % self.ntag;
self.ntag+=1;
self.text.tag_add(tag, first, last);
def cmd(e=None):
self.menucopy.setTextTag(label, text);
if ismacos:
self.text.tag_bind(tag, "<Button-2>", cmd);
else:
self.text.tag_bind(tag, "<Button-3>", cmd);
def addTextWithCopyCmd(self, index, textcopy, textcmd):
index = self.text.index(index);
tag = "btncopy%d" % self.ntag;
self.ntag+=1;
def copythis(e):
self._Copy(e, index, textcopy);
self.text.insert(index, " "); #<-separator
self.text.insert(index+"+1c", textcmd, ("btncursor2", "btncopy", tag));
self.text.tag_bind(tag, "<Button-1>", copythis); #clic event
def _cursor2(self, event=None):
self.text.configure(cursor="hand2");
def _cursorNormal(self, event=None):
self.text.configure(cursor="");
def _Copy(self, event, index, string):
""" event copy by user, add a tag message 'copied' """
self.clipboard_clear();
self.clipboard_append(string);
m = self.fontTextNormal.metrics();
d = m["descent"];
height = m["linespace"]+d;
x,y,w,h = self.text.bbox(index);
w = self.fontTextNormal.measure("_")*9; #self.stateCopy.winfo_width();
self.stateCopy.place(x=event.x-w//2, y=y-height-d*2, height=height);
if self._idEventHiddenCopy:
self.after_cancel(self._idEventHiddenCopy);
self._idEventHiddenCopy = self.after(1000, self.stateCopy.place_forget);
class HelpFrameSecond(HelpFrame):
""" frame component, when use the program """
def __init__(self, master, themes, messages):
HelpFrame.__init__(self, master, themes, messages);
self.btnClose = Button(self.frame2, bd=1, text="Close", command=self.master.destroy);
self.btnClose.pack(side="right", padx=15);
class HelpForm(Toplevel):
""" window Help, About: when use the program (by menu), after use the program """
def __init__(self, master, title, themes, messages):
Toplevel.__init__(self, master);
self.title(title);
self.geometry("580x420");
self.minsize(550,420);
self.maxsize(800,530);
self.transient(master);
ext_funcs.center_window(master, self);
frame = HelpFrameSecond(self, themes, messages );
self.focus_set();
self.grab_set();
def __str__(self):
return "help_form"; #for interrupts from outside
class LicenceShowForm(Tk):
""" window, when start the program, first time """
def __init__(self, title, themes, messages):
Tk.__init__(self);
self.withdraw();
self.title(title);
self.geometry("580x420");
self.minsize(550,420);
self.maxsize(800,530);
self.frame = HelpFrame(self, themes, messages );
self.btnAcept = Button(self.frame.frame2, text="Ok", command=self.destroy);
self.btnAcept.pack(side="right", padx=10, ipadx=20);
#self.protocol("WM_DELETE_WINDOW", self.No);
self._centerToScreen();
def _centerToScreen(self):
self.update_idletasks();
width, height = self.winfo_width(), self.winfo_height();
centerX, centerY = self.winfo_screenwidth()//2,self.winfo_screenheight()//2;
x = centerX-width//2;
y = centerY-height//2;
self.geometry("+%d+%d" % (x,y));
self.deiconify();
def About(master):
return HelpForm(master, "About",
("About","Licence"),
({"en": help_strings._about_,
"es": help_strings._about_esp_}, help_strings._license_),
);
def Help(master):
return HelpForm(master, "Help",
("Help",),
({"en": help_strings._help_,"es": help_strings._help_esp_},),
);
def FirstTimeLicense(config_save):
win = LicenceShowForm("License",
("Licence", "About", "Help"),
(help_strings._license_,
{"en": help_strings._about_,"es": help_strings._about_esp_},
{"en": help_strings._help_,"es": help_strings._help_esp_},
),
);
win.mainloop();
config_save["showed_license"] = True;
config_save.save();
_fontnames.clear();
return;
if __name__ == "__main__":
#try:
from tkinter import Tk;
#except ImportError:
# from Tkinter import Tk;
root = Tk();
root.geometry("250x100");
root.title("dev:: test");
about_cmd = lambda: About(root);
help_cmd = lambda: Help(root);
Button(root, text="About", command=about_cmd).pack();
Button(root, text="Help", command=help_cmd).pack();
root.mainloop();