Advertisement
here2share

# cycle_entry_focus.py

May 23rd, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. # cycle_entry_focus.py
  2.  
  3. from Tkinter import *
  4.  
  5. master = Tk()
  6. Label(master, text="1st: ").grid(row=0)
  7. Label(master, text="2nd: ").grid(row=1)
  8. Label(master, text="3rd: ").grid(row=2)
  9. Label(master, text="4th: ").grid(row=3)
  10.  
  11. e1 = Entry(master)
  12. e2 = Entry(master)
  13. e3 = Entry(master)
  14. e4 = Entry(master)
  15.  
  16. e1.grid(row=0, column=1)
  17. e2.grid(row=1, column=1)
  18. e3.grid(row=2, column=1)
  19. e4.grid(row=3, column=1)
  20.  
  21. def go_to_next_entry(event, entry_list, this_index):
  22.     next_index = (this_index + 1) % len(entry_list)
  23.     entry_list[next_index].focus_set()
  24.  
  25. entries = [child for child in master.winfo_children() if isinstance(child, Entry)]
  26. for idx, entry in enumerate(entries):
  27.     entry.bind('<Return>', lambda e, idx=idx: go_to_next_entry(e, entries, idx))
  28.  
  29. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement