Skip to content

Commit

Permalink
Fixed input validation to work using the correct validatecommand tkin…
Browse files Browse the repository at this point in the history
…ter method - this also fixes the previous problems with backspace
  • Loading branch information
Levtastic committed Jun 8, 2015
1 parent 471d86d commit 2e1b8af
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions countdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ def _layout(self, root):
l = ttk.Label(f, text = 'Letters:', font = layoutFont)
l.pack(side = tk.TOP, anchor = tk.W)

eLetters = tk.Entry(f, font = layoutFont)
eLetters = tk.Entry(f, font = layoutFont, validate = 'key')
vcmd = eLetters.register(self.validate_input)
eLetters.config(validatecommand = (vcmd, '%d', '%S'))
eLetters.pack(side = tk.TOP, fill = tk.X, expand = True)
eLetters.bind('<Key>', self._validate_input)
eLetters.bind('<Control-a>', self._select_all)
eLetters.focus()

Expand All @@ -60,11 +61,11 @@ def _layout(self, root):
bCalculate.configure(command = calc)
eLetters.bind('<Return>', calc)

def _validate_input(self, event):
if event.char and event.char not in 'abcdefghijklmnopqrstuvqxyz':
return 'break'
def validate_input(self, action, key):
if action == '1' and key not in 'abcdefghijklmnopqrstuvwxyz':
return False

return None
return True

def _select_all(self, event):
event.widget.select_range(0, tk.END)
Expand Down

0 comments on commit 2e1b8af

Please sign in to comment.