maybe_save_Dialog.py
directory : D:\2018_py_proj\TkGridGUI\tkgridgui
Line Count : 192
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
9
10
11
12
13 from future import standard_library
14 standard_library.install_aliases()
15 from builtins import object
16 import sys
17
18 if sys.version_info < (3,):
19 from tkSimpleDialog import Dialog
20 else:
21 from tkinter.simpledialog import Dialog
22
23 from tkinter import *
24 from tkinter import Button, Canvas, Checkbutton, Entry, Frame, Label, LabelFrame
25 from tkinter import Listbox, Message, Radiobutton, Spinbox, Text
26 from tkinter import OptionMenu
27 from tkinter.ttk import Combobox, Progressbar, Separator, Treeview, Style, Notebook
28
29 from tkinter import _setit as set_command
30
31
32
33
34
35
36
37 class _Dialog(Dialog):
38
39 def __init__(self, parent, title = None, dialogOptions=None):
40
41 self.dialogOptions = dialogOptions
42 Dialog.__init__(self, parent, title)
43
44 class maybe_save_dialog(_Dialog):
45
46 def buttonbox(self):
47 pass
48
49
50
51 def body(self, master):
52 dialogframe = Frame(master, width=321, height=110)
53 self.dialogframe = dialogframe
54 dialogframe.pack()
55
56
57 self.make_Button_1( self.dialogframe )
58 self.make_Button_2( self.dialogframe )
59 self.make_Label_1( self.dialogframe )
60 self.make_Label_2( self.dialogframe )
61 self.make_Label_3( self.dialogframe )
62 self.make_Label_4( self.dialogframe )
63
64
65
66
67 self.save_file = False
68
69
70
71 def make_Button_1(self, frame):
72 """ Button: Save File : at Main(4,1)"""
73 self.Button_1 = Button( frame , text="Save File", width="15")
74 self.Button_1.grid(row=4, column=1)
75
76
77
78 self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click)
79
80
81 def make_Button_2(self, frame):
82 """ Button: Do NOT Save : at Main(4,3)"""
83 self.Button_2 = Button( frame , text="Do NOT Save", width="15")
84 self.Button_2.grid(row=4, column=3)
85
86
87
88 self.Button_2.bind("<ButtonRelease-1>", self.Button_2_Click)
89
90
91 def make_Label_1(self, frame):
92 """ Label: Current File has Changed : at Main(1,1)"""
93 self.Label_1 = Label( frame , text="Current File has Changed", width="45")
94 self.Label_1.grid(row=1, column=1, columnspan="3")
95
96
97
98
99
100 def make_Label_2(self, frame):
101 """ Label: Do you want to Save before Continuing? : at Main(2,1)"""
102 self.Label_2 = Label( frame , text="Do you want to Save before Continuing?", width="45")
103 self.Label_2.grid(row=2, column=1, columnspan="3")
104
105
106
107
108
109 def make_Label_3(self, frame):
110 """ Label: at Main(3,1)"""
111 self.Label_3 = Label( frame , text="", width="15")
112 self.Label_3.grid(row=3, column=1)
113
114
115
116
117
118 def make_Label_4(self, frame):
119 """ Label: at Main(5,1)"""
120 self.Label_4 = Label( frame , text="", width="15")
121 self.Label_4.grid(row=5, column=1)
122
123
124
125
126
127 def Button_1_Click(self, event):
128 """ Button: Save File : at Main(4,1)"""
129 pass
130
131
132
133 self.save_file = True
134 self.ok()
135
136
137 def Button_2_Click(self, event):
138 """ Button: Do NOT Save : at Main(4,3)"""
139 pass
140
141
142
143 self.save_file = False
144 self.ok()
145
146
147 def validate(self):
148 self.result = {}
149
150
151
152
153
154
155
156
157 if self.save_file:
158 self.result["save_file"] = "yes"
159 else:
160 self.result["save_file"] = "no"
161 return 1
162
163
164
165 def apply(self):
166
167 pass
168
169 class _Testdialog(object):
170 def __init__(self, master):
171 frame = Frame(master, width=300, height=300)
172 frame.pack()
173 self.master = master
174 self.x, self.y, self.w, self.h = -1,-1,-1,-1
175
176 self.Button_1 = Button(text="Test Dialog", relief="raised", width="15")
177 self.Button_1.place(x=84, y=36)
178 self.Button_1.bind("<ButtonRelease-1>", self.Button_1_Click)
179
180 def Button_1_Click(self, event):
181 dialog = maybe_save_dialog(self.master, "Test Dialog")
182 print( '===============Result from Dialog====================' )
183 print( dialog.result )
184 print( '=====================================================' )
185
186 def main():
187 root = Tk()
188 app = _Testdialog(root)
189 root.mainloop()
190
191 if __name__ == '__main__':
192 main()
193