-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkSimpleDialog.py
More file actions
184 lines (142 loc) · 5.07 KB
/
Copy pathtkSimpleDialog.py
File metadata and controls
184 lines (142 loc) · 5.07 KB
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
'''
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Creating a simple dialog, revisited
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
https://effbot.org/tkinterbook/tkinter-dialog-windows.htm
## example implementation:
import tkinter as tk
import tkSimpleDialog
class MyDialog(tkSimpleDialog.Dialog):
# this method overrides the one in the Dialog class (below)
def body(self, parent):
tk.Label(parent, text="First:").grid(row=0)
tk.Label(parent, text="Second:").grid(row=1)
self.e1 = tk.Entry(parent)
self.e2 = tk.Entry(parent)
self.e1.grid(row=0, column=1)
self.e2.grid(row=1, column=1)
return self.e1 # initial focus
# this method overrides the one in the Dialog class (below)
def apply(self):
first = int(self.e1.get())
second = int(self.e2.get())
print(first, second) # or something
'''
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
"""
file: tkSimpleDialog.py
the methods from tkSimpleDialog are used in
-- messagebox_dark.py
-- settings.py
"""
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#from Tkinter import *
import tkinter as tk
import os
""" V V V V V V Styled DARK for OnStep Console V V V V V V V V """
class Dialog(tk.Toplevel):
def __init__(self, parent, windowTitle=None, text=None):
tk.Toplevel.__init__(self, parent)
self.transient(parent)
self.attributes('-topmost',True)
if windowTitle:
self.title=windowTitle
else:
self.title="Settings"
self.parent = parent
self.text=text
self.result = None
self._bg='gray19'
self._fg='tomato'
self.config(bg=self._bg)
body = tk.Frame(self)
body.config(bg=self._bg)
self.initial_focus = self.body(body,self.title,self.text)
body.pack(padx=20, pady=20)
self.buttonbox()
self.grab_set()
if not self.initial_focus:
self.initial_focus = self
self.protocol("WM_DELETE_WINDOW", self.cancel)
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
parent.winfo_rooty()+50))
self.initial_focus.focus_set()
self.wait_window(self)
#
# construction hooks
#
def body(self, parent, title, text): # THIS METHOD must BE OVERRIDDEN
# create dialog body.
# return widget that should have initial focus.
pass
""" V V V V V V Styled DARK for OnStep Console V V V V V V V V """
def buttonbox(self):
# add standard button box.
# override if you don't want the standard buttons
box = tk.Frame(self)
box.config(bg=self._bg)
w = tk.Button(box, text="Cancel", width=10, command=self.cancel)
w.config(bg=self._bg, fg=self._fg, pady=4, activebackground='goldenrod1')
w.config(highlightbackground='goldenrod1')
w.config(highlightcolor='red')
w.config(highlightthickness=1)
w.pack(side='left')
w = tk.Button(box, text="OK", width=10, command=self.ok)
w.config(bg=self._bg, fg=self._fg, pady=4, activebackground='red')
w.config(highlightbackground='red')
w.config(highlightcolor='green2')
w.config(highlightthickness=1)
#w.pack(side='left', padx=5, pady=5)
w.pack(side='left')
self.bind("<Return>", self.ok)
self.bind("<Escape>", self.cancel)
box.pack()
#
# standard button semantics
#
def ok(self, event=None):
if not self.valid_input():
self.initial_focus.focus_set() # put focus back
return
self.withdraw()
self.update_idletasks()
result = self.apply()
self.cancel(result)
def cancel(self, result=False, event=None):
# put focus back to the parent window
self.parent.focus_set()
self.destroy()
return result
def yes(self, event=None):
self.withdraw()
self.update_idletasks()
self.parent.focus_set()
self.destroy()
return "Yes"
def no(self, event=None):
self.withdraw()
self.update_idletasks()
self.parent.focus_set()
self.destroy()
return "No"
#
# command hooks
#
def valid_input(self): # THIS METHOD COULD BE OVERRIDDEN
return 0 # OVERRIDE
def apply(self): # THIS METHOD must BE OVERRIDDEN
pass # OVERRIDE
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
'''
showinfo, showwarning, showerror,
askquestion, askokcancel, askyesno, or askretrycancel
'''
## # try:
## # fp = open(filename)
## # except:
## # tkMessageBox.showwarning(
## # "Open file",
## # "Cannot open this file\n(%s)" % filename
## # )
## # return
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #