Python Forum
[Tkinter] how to move between text entries using the keyboard?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] how to move between text entries using the keyboard?
#2
Bind an event on a control to '<Return>', in the event handler give the next control focus.

import tkinter as tk


class MainFrame(tk.Frame):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.entry1 = tk.Entry(self.master)
        self.entry1.pack()
        self.entry2 = tk.Entry(self.master)
        self.entry2.pack()
        self.entry3 = tk.Entry(self.master)
        self.entry3.pack()
        self.entry1.bind('<Return>', self.on_entry1_return)
        self.entry2.bind('<Return>', self.on_entry2_return)

    def on_entry1_return(self, event):
        self.entry2.focus_set()

    def on_entry2_return(self, event):
        self.entry3.focus_set()


if __name__ == '__main__':
    app = tk.Tk()
    main_frame = MainFrame()
    app.mainloop()
Reply


Messages In This Thread
RE: how to move between text entries using the keyboard? - by Yoriz - Jun-09-2019, 11:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to move in entries using the arrow keys by applying the bind and focus? pymn 4 4,712 Apr-06-2022, 04:29 AM
Last Post: pymn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020