11"""
22Dialog for building Tkinter accelerator key bindings
33"""
4- from tkinter import *
5- from tkinter .ttk import Scrollbar
4+ from tkinter import Toplevel , Listbox , Text , StringVar , TclError
5+ from tkinter .ttk import Button , Checkbutton , Entry , Frame , Label , Scrollbar
66from tkinter import messagebox
77import string
88import sys
@@ -67,11 +67,11 @@ def showerror(self, *args, **kwargs):
6767 messagebox .showerror (* args , ** kwargs )
6868
6969 def create_widgets (self ):
70- self .frame = frame = Frame (self , borderwidth = 2 , relief = SUNKEN )
71- frame .pack (side = TOP , expand = True , fill = BOTH )
70+ self .frame = frame = Frame (self , borderwidth = 2 , relief = 'sunken' )
71+ frame .pack (side = 'top' , expand = True , fill = 'both' )
7272
7373 frame_buttons = Frame (self )
74- frame_buttons .pack (side = BOTTOM , fill = X )
74+ frame_buttons .pack (side = 'bottom' , fill = 'x' )
7575
7676 self .button_ok = Button (frame_buttons , text = 'OK' ,
7777 width = 8 , command = self .ok )
@@ -82,20 +82,20 @@ def create_widgets(self):
8282
8383 # Basic entry key sequence.
8484 self .frame_keyseq_basic = Frame (frame , name = 'keyseq_basic' )
85- self .frame_keyseq_basic .grid (row = 0 , column = 0 , sticky = NSEW ,
85+ self .frame_keyseq_basic .grid (row = 0 , column = 0 , sticky = 'nsew' ,
8686 padx = 5 , pady = 5 )
8787 basic_title = Label (self .frame_keyseq_basic ,
8888 text = f"New keys for '{ self .action } ' :" )
89- basic_title .pack (anchor = W )
89+ basic_title .pack (anchor = 'w' )
9090
91- basic_keys = Label (self .frame_keyseq_basic , justify = LEFT ,
92- textvariable = self .key_string , relief = GROOVE ,
91+ basic_keys = Label (self .frame_keyseq_basic , justify = 'left' ,
92+ textvariable = self .key_string , relief = 'groove' ,
9393 borderwidth = 2 )
94- basic_keys .pack (ipadx = 5 , ipady = 5 , fill = X )
94+ basic_keys .pack (ipadx = 5 , ipady = 5 , fill = 'x' )
9595
9696 # Basic entry controls.
9797 self .frame_controls_basic = Frame (frame )
98- self .frame_controls_basic .grid (row = 1 , column = 0 , sticky = NSEW , padx = 5 )
98+ self .frame_controls_basic .grid (row = 1 , column = 0 , sticky = 'nsew' , padx = 5 )
9999
100100 # Basic entry modifiers.
101101 self .modifier_checkbuttons = {}
@@ -105,51 +105,51 @@ def create_widgets(self):
105105 check = Checkbutton (self .frame_controls_basic ,
106106 command = self .build_key_string , text = label ,
107107 variable = variable , onvalue = modifier , offvalue = '' )
108- check .grid (row = 0 , column = column , padx = 2 , sticky = W )
108+ check .grid (row = 0 , column = column , padx = 2 , sticky = 'w' )
109109 self .modifier_checkbuttons [modifier ] = check
110110 column += 1
111111
112112 # Basic entry help text.
113- help_basic = Label (self .frame_controls_basic , justify = LEFT ,
113+ help_basic = Label (self .frame_controls_basic , justify = 'left' ,
114114 text = "Select the desired modifier keys\n " +
115115 "above, and the final key from the\n " +
116116 "list on the right.\n \n " +
117117 "Use upper case Symbols when using\n " +
118118 "the Shift modifier. (Letters will be\n " +
119119 "converted automatically.)" )
120- help_basic .grid (row = 1 , column = 0 , columnspan = 4 , padx = 2 , sticky = W )
120+ help_basic .grid (row = 1 , column = 0 , columnspan = 4 , padx = 2 , sticky = 'w' )
121121
122122 # Basic entry key list.
123123 self .list_keys_final = Listbox (self .frame_controls_basic , width = 15 ,
124- height = 10 , selectmode = SINGLE )
124+ height = 10 , selectmode = 'single' )
125125 self .list_keys_final .bind ('<ButtonRelease-1>' , self .final_key_selected )
126- self .list_keys_final .grid (row = 0 , column = 4 , rowspan = 4 , sticky = NS )
126+ self .list_keys_final .grid (row = 0 , column = 4 , rowspan = 4 , sticky = 'ns' )
127127 scroll_keys_final = Scrollbar (self .frame_controls_basic ,
128- orient = VERTICAL ,
128+ orient = 'vertical' ,
129129 command = self .list_keys_final .yview )
130130 self .list_keys_final .config (yscrollcommand = scroll_keys_final .set )
131- scroll_keys_final .grid (row = 0 , column = 5 , rowspan = 4 , sticky = NS )
131+ scroll_keys_final .grid (row = 0 , column = 5 , rowspan = 4 , sticky = 'ns' )
132132 self .button_clear = Button (self .frame_controls_basic ,
133133 text = 'Clear Keys' ,
134134 command = self .clear_key_seq )
135135 self .button_clear .grid (row = 2 , column = 0 , columnspan = 4 )
136136
137137 # Advanced entry key sequence.
138138 self .frame_keyseq_advanced = Frame (frame , name = 'keyseq_advanced' )
139- self .frame_keyseq_advanced .grid (row = 0 , column = 0 , sticky = NSEW ,
139+ self .frame_keyseq_advanced .grid (row = 0 , column = 0 , sticky = 'nsew' ,
140140 padx = 5 , pady = 5 )
141- advanced_title = Label (self .frame_keyseq_advanced , justify = LEFT ,
141+ advanced_title = Label (self .frame_keyseq_advanced , justify = 'left' ,
142142 text = f"Enter new binding(s) for '{ self .action } ' :\n " +
143143 "(These bindings will not be checked for validity!)" )
144- advanced_title .pack (anchor = W )
144+ advanced_title .pack (anchor = 'w' )
145145 self .advanced_keys = Entry (self .frame_keyseq_advanced ,
146146 textvariable = self .key_string )
147- self .advanced_keys .pack (fill = X )
147+ self .advanced_keys .pack (fill = 'x' )
148148
149149 # Advanced entry help text.
150150 self .frame_help_advanced = Frame (frame )
151- self .frame_help_advanced .grid (row = 1 , column = 0 , sticky = NSEW , padx = 5 )
152- help_advanced = Label (self .frame_help_advanced , justify = LEFT ,
151+ self .frame_help_advanced .grid (row = 1 , column = 0 , sticky = 'nsew' , padx = 5 )
152+ help_advanced = Label (self .frame_help_advanced , justify = 'left' ,
153153 text = "Key bindings are specified using Tkinter keysyms as\n " +
154154 "in these samples: <Control-f>, <Shift-F2>, <F12>,\n "
155155 "<Control-space>, <Meta-less>, <Control-Alt-Shift-X>.\n "
@@ -159,12 +159,12 @@ def create_widgets(self):
159159 "is the 'do-nothing' keybinding.\n \n " +
160160 "Multiple separate bindings for one action should be\n " +
161161 "separated by a space, eg., <Alt-v> <Meta-v>." )
162- help_advanced .grid (row = 0 , column = 0 , sticky = NSEW )
162+ help_advanced .grid (row = 0 , column = 0 , sticky = 'nsew' )
163163
164164 # Switch between basic and advanced.
165165 self .button_level = Button (frame , command = self .toggle_level ,
166166 text = '<< Basic Key Binding Entry' )
167- self .button_level .grid (row = 2 , column = 0 , stick = EW , padx = 5 , pady = 5 )
167+ self .button_level .grid (row = 2 , column = 0 , stick = 'ew' , padx = 5 , pady = 5 )
168168 self .toggle_level ()
169169
170170 def set_modifiers_for_platform (self ):
@@ -204,7 +204,7 @@ def final_key_selected(self, event=None):
204204 def build_key_string (self ):
205205 "Create formatted string of modifiers plus the key."
206206 keylist = modifiers = self .get_modifiers ()
207- final_key = self .list_keys_final .get (ANCHOR )
207+ final_key = self .list_keys_final .get ('anchor' )
208208 if final_key :
209209 final_key = self .translate_key (final_key , modifiers )
210210 keylist .append (final_key )
@@ -217,8 +217,8 @@ def get_modifiers(self):
217217
218218 def clear_key_seq (self ):
219219 "Clear modifiers and keys selection."
220- self .list_keys_final .select_clear (0 , END )
221- self .list_keys_final .yview (MOVETO , '0.0' )
220+ self .list_keys_final .select_clear (0 , 'end' )
221+ self .list_keys_final .yview ('moveto' , '0.0' )
222222 for variable in self .modifier_vars :
223223 variable .set ('' )
224224 self .key_string .set ('' )
@@ -237,7 +237,7 @@ def load_final_key_list(self):
237237 # Make a tuple of most of the useful common 'final' keys.
238238 keys = (self .alphanum_keys + self .punctuation_keys + self .function_keys +
239239 self .whitespace_keys + self .edit_keys + self .move_keys )
240- self .list_keys_final .insert (END , * keys )
240+ self .list_keys_final .insert ('end' , * keys )
241241
242242 @staticmethod
243243 def translate_key (key , modifiers ):
@@ -282,7 +282,7 @@ def keys_ok(self, keys):
282282 Doesn't check the string produced by the advanced dialog because
283283 'modifiers' isn't set.
284284 """
285- final_key = self .list_keys_final .get (ANCHOR )
285+ final_key = self .list_keys_final .get ('anchor' )
286286 modifiers = self .get_modifiers ()
287287 title = self .keyerror_title
288288 key_sequences = [key for keylist in self .current_key_sequences
0 commit comments