menu_maker_Dialog.py
directory : D:\2018_py_proj\TkGridGUI\tkgridgui
Line Count : 137
Line Clip Size : No Clipping
tab_of_notebook_changed Word MatchCase (0)
1
2
3 from __future__ import print_function
4 from __future__ import unicode_literals
5
6
7
8 from future import standard_library
9 standard_library.install_aliases()
10 from builtins import object
11 import sys
12
13 if sys.version_info < (3,):
14 from tkSimpleDialog import Dialog
15 else:
16 from tkinter.simpledialog import Dialog
17
18 from tkinter import *
19
20 class _Dialog(Dialog):
21
22 def __init__(self, parent, title = None, dialogOptions=None):
23 self.dialogOptions = dialogOptions
24 Dialog.__init__(self, parent, title)
25
26 class Menumaker(_Dialog):
27
28 def buttonbox(self):
29 pass
30
31
32
33 def body(self, master):
34 dialogframe = Frame(master, width=300, height=500)
35 dialogframe.pack()
36
37 self.Button_1 = Button(dialogframe,text="Save Menu", relief="raised", width="15")
38 self.Button_1.place(x=24, y=12)
39 self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click)
40
41 self.Button_2 = Button(dialogframe,text="Exit Without Saving", relief="raised", width="15")
42 self.Button_2.place(x=173, y=12)
43 self.Button_2.bind("<ButtonRelease-1>", self.Button_2_Click)
44
45 self.Label_1 = Label(dialogframe,pady="1", text="Be Consistent with Indents", width="30")
46 self.Label_1.place(x=60, y=72)
47
48 self.ctrl_keyChkBox_StringVar = StringVar()
49 self.ctrl_keyChkBox = Checkbutton(dialogframe, text="Create ctrl-key shortcuts", width="30")
50 self.ctrl_keyChkBox.place(x=24 ,y=90 )
51 self.ctrl_keyChkBox.configure( onvalue="yes", offvalue="no", variable=self.ctrl_keyChkBox_StringVar)
52 self.ctrl_keyChkBox_StringVar.set("yes")
53
54 self.Message_1 = Message(dialogframe,text="Indent Text To Show Menu Structure", aspect="1000", relief="flat")
55 self.Message_1.place(x=57, y=46)
56
57 self.Text_1 = Text(dialogframe,padx="1", width="35", height="30")
58 self.Text_1.place(x=12, y=120)
59
60 if self.dialogOptions:
61 self.Text_1.insert(END, self.dialogOptions )
62
63
64 def Master_Configure(self, event):
65 if event.widget != self.master:
66 if self.w != -1:
67 return
68 x = self.master.winfo_x()
69 y = self.master.winfo_y()
70 w = self.master.winfo_width()
71 h = self.master.winfo_height()
72 if (self.x, self.y, self.w, self.h) == (-1,-1,-1,-1):
73 self.x, self.y, self.w, self.h = x,y,w,h
74
75
76
77
78 def Button_1_Click(self, event):
79
80 self.ok()
81
82 def Button_2_Click(self, event):
83
84 self.cancel()
85
86 def validate(self):
87 self.result = {}
88
89
90
91
92
93 self.result["test"] = "test message"
94
95 self.result["menu"] = self.Text_1.get(1.0, END)
96
97 self.result["add_menu_ctrl_keys"] = self.ctrl_keyChkBox_StringVar.get()
98
99 if sys.version_info >= (3,):
100
101
102 pass
103
104
105
106 return 1
107
108
109
110 def apply(self):
111
112 pass
113
114 class _Testdialog(object):
115 def __init__(self, master):
116 frame = Frame(master, width=300, height=300)
117 frame.pack()
118 self.master = master
119 self.x, self.y, self.w, self.h = -1,-1,-1,-1
120
121 self.Button_1 = Button(text="Test Dialog", relief="raised", width="15")
122 self.Button_1.place(x=84, y=36)
123 self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click)
124
125 def Button_1_Click(self, event):
126 dialog = Menumaker(self.master, "Test Dialog",'File\n New\n Save')
127 print( '===============Result from Dialog====================' )
128 print( dialog.result )
129 print( '=====================================================' )
130
131 def main():
132 root = Tk()
133 app = _Testdialog(root)
134 root.mainloop()
135
136 if __name__ == '__main__':
137 main()
138