Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] how to move between text entries using the keyboard?
#1
i have a gui with text entries being assigned to variables and then written into files. but right now i have to go each time with my moust to the next entry. how do i make it so pressing enter will go to the next entry in window? or that pressing enter would submit they entry opening the next popup in the sequence?

i have:
import re
from tkinter import *
from tkinter import ttk
import tkinter as tk

root = Tk(  )

global circle2centerx
global circle2centery
global circle2radius

circle2centerx = StringVar()
circle2centery = StringVar()
circle2radius = StringVar()

def savedata():


    global circle2centerx_info
    global circle2centerx_entry
    global circle2centery_info
    global circle2centery_entry
    global circle2radius_info
    global circle2radius_entry
    circle2centerx_info = circle2centerx.get()
    circle2centery_info = circle2centery.get()
    circle2radius_info = circle2radius.get()
    my_function()

def my_function():
    circle2centerx_info = circle2centerx.get()
    circle2centery_info = circle2centery.get()
    circle2radius_info = circle2radius.get()

def circle2():
  
  with open("C:/Users/mr big/Dropbox/code/python/markers replace/content to be inserted/extend script functions/circle2.txt", 'r') as myfile:
      text = myfile.read()
  with open("C:/Users/mr big/Desktop/made function/active gui/write in 1.txt", "a") as myfile2:
      my_function()
      myfile2.write(circle2centerx_info +"," + circle2centery_info +"," + circle2radius_info)

def circle2entry(): # new window definition
    global circle2centerx_info
    global circle2centerx_entry
    global circle2centery_info
    global circle2centery_entry
    global circle2radius_info
    global circle2radius_entry


    Label(circle2window, text = "circle2 center x * ").pack() 
    circle2centerx_entry = Entry(circle2window, textvariable = circle2centerx)
    circle2centerx_entry.pack()  

    Label(circle2window, text = "circle2 center y * ").pack() 
    circle2centery_entry = Entry(circle2window, textvariable = circle2centery)
    circle2centery_entry.pack()  

    Label(circle2window, text = "circle2 radius * ").pack() 
    circle2radius_entry = Entry(circle2window, textvariable = circle2radius)
    circle2radius_entry.pack()  


    Label(circle2window, text = "").pack()
    Button(circle2window, text = "savedata", width = 10, height = 1, command = savedata).pack()
    Label(circle2window, text = "").pack()
    Button(circle2window, text = "write function", width = 10, height = 1, command = circle2).pack()




Label(root, text = "").pack()
Button(root, text = "circle2", width = 100, height = 1, command = circle2entry).pack()



#Menu Bar

menu = Menu(root)
root.config(menu=menu)

file = Menu(menu)


file.add_command(label = 'Exit', command = lambda:exit())






root.mainloop()
Yoriz wrote Jun-09-2019, 10:48 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#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()
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)