Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # cycle_entry_focus.py
- from Tkinter import *
- master = Tk()
- Label(master, text="1st: ").grid(row=0)
- Label(master, text="2nd: ").grid(row=1)
- Label(master, text="3rd: ").grid(row=2)
- Label(master, text="4th: ").grid(row=3)
- e1 = Entry(master)
- e2 = Entry(master)
- e3 = Entry(master)
- e4 = Entry(master)
- e1.grid(row=0, column=1)
- e2.grid(row=1, column=1)
- e3.grid(row=2, column=1)
- e4.grid(row=3, column=1)
- def go_to_next_entry(event, entry_list, this_index):
- next_index = (this_index + 1) % len(entry_list)
- entry_list[next_index].focus_set()
- entries = [child for child in master.winfo_children() if isinstance(child, Entry)]
- for idx, entry in enumerate(entries):
- entry.bind('<Return>', lambda e, idx=idx: go_to_next_entry(e, entries, idx))
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement