@@ -132,6 +132,10 @@ def show(self):
132
132
133
133
134
134
class CloppyButtonWindow (CloppyWindow ):
135
+ """
136
+ A sub-child of CloppyWindow that takes input from the user using a list of
137
+ buttons.
138
+ """
135
139
def __init__ (self , master ):
136
140
super ().__init__ (master )
137
141
@@ -159,8 +163,6 @@ def add_choice(self, choice):
159
163
command = lambda : self .make_choice (choice )
160
164
)
161
165
162
- # choice_button.bind('<Up>', self.on_up_key)
163
-
164
166
row = len (self .choice_buttons )
165
167
166
168
choice_button .grid (
@@ -174,12 +176,20 @@ def add_choice(self, choice):
174
176
def show (self ):
175
177
super ().show ()
176
178
179
+ # Set focus to the first button in the list.
177
180
if len (self .choice_buttons ):
178
181
self .choice_buttons [0 ].focus_set ()
179
182
180
183
def set_highlighted_choice (self , choice ):
184
+ """
185
+ Set focus to the button at a given index in the list of choices.
186
+
187
+ :param choice: The index of the choice to be focused on.
188
+ """
189
+
181
190
if choice < 0 :
182
191
choice = len (self .choice_buttons )- 1
192
+
183
193
elif choice >= len (self .choice_buttons ):
184
194
choice = 0
185
195
@@ -197,27 +207,45 @@ def on_enter_key(self, event: tk.Event):
197
207
198
208
199
209
class CloppyTextInputWindow (CloppyWindow ):
210
+ """
211
+ A sub-child of CloppyWindow that takes input from the user using a text
212
+ entry.
213
+ """
200
214
def __init__ (self , master , password = False , submit_button_text = 'Ok' ):
215
+ """
216
+ :param password: If set to True, then input in the box will be masked
217
+ as if it's a password.
218
+
219
+ :param submit_button_text: The text shown in the button at the bottom.
220
+ When clicked, this button will submit the
221
+ user's input as a choice.
222
+ """
201
223
super ().__init__ (master )
202
224
225
+ # Setting up the text entry box.
203
226
if password :
204
227
self .input_box = tk .Entry (self .input_frame , show = '*' )
205
228
else :
206
229
self .input_box = tk .Entry (self .input_frame )
207
230
231
+ self .input_box .grid (row = 0 , column = 0 , sticky = tk .NSEW )
232
+
233
+ self .input_box .bind (
234
+ '<Return>' ,
235
+ lambda e : self .make_choice (self .input_box .get ())
236
+ )
237
+
238
+ # Setting up the submit button.
208
239
self .submit_button = tk .Button (
209
240
self .input_frame ,
210
241
text = submit_button_text ,
211
242
command = lambda : self .make_choice (self .input_box .get ())
212
243
)
213
244
214
- self .input_box .grid (row = 0 , column = 0 , sticky = tk .NSEW )
215
245
self .submit_button .grid (row = 1 , column = 0 , sticky = tk .NSEW )
216
- self .input_box .bind (
217
- '<Return>' ,
218
- lambda e : self .make_choice (self .input_box .get ())
219
- )
220
246
221
247
def show (self ):
222
248
super ().show ()
249
+
250
+ # Direct focus to the input box.
223
251
self .input_box .focus_set ()
0 commit comments