Home > other >  Python 3.6 and press enter key to achieve what should I do to focus in order down
Python 3.6 and press enter key to achieve what should I do to focus in order down

Time:01-16

Write a computer program, don't know how to do it, with the Entry as to get the data input box
Now I want to press the return key, let focus down in sequence, it is easy to input data,
Rswitch code to put in the following way (),


 # coding=utf-8 
# python version 3.6
The from tkinter import *
The from tkinter import messagebox


Xname=[]

The class Application (Frame) :
Def __init__ (self, master=None) :
Super () __init__ (master)
The self. The master=master
The self. The pack ()
Self. Aptly named createWidget ()
Self. Master. Bind (" & lt; Return>" , the self. Rswitch)

Def aptly named createWidget (self) :
For I in range (29) :
Lab01=Label (self, text=I * 2 + 4)
Lab01. The grid (row=I, the column=0)
For c in range (7) :
For r in the range (29) :
Xname. Append (Entry (self, width=10))
Xname [29 + c * r]. The grid (row=r, the column=c + 1)
Xname [0]. Focus_set ()

Def rswitch (self, event) :
"" "want to implement a function here, is at the time of press the return key, the focus of the Entry in order move down "" "


If __name__=="__main__" :
Root=Tk ()
Root. Geometry (" 800 x600 + 200 + 200)
Root. Title (" application ")
App=Application (root)
Root. Mainloop ()

CodePudding user response:

I have an immature idea is only for reference:
1, to each Entry components are binding "enter" event, and then calls rswitch ()
2, through the event in rswitch. The current focus is on which Entry widget judgment, press the enter key to set focus to wish the next component in the
3, in numerous Entry should be some position, according to the correlation to move the focus,
Such as: xname containing are examples of Entry, the xname. Index (event. The widget) whether can obtain the index value

If possible just give it a try, hope to useful,

CodePudding user response:

Yes, feasible, I put xname subscript work it out can achieve reasonable switch,

CodePudding user response:

reference 1st floor DuskCrow_ response:
I have an immature idea is only for reference:
1, to each Entry components are binding "enter" event, and then calls rswitch ()
2, through the event in rswitch. The current focus is on which Entry widget judgment, press the enter key to set focus to wish the next component in the
3, in numerous Entry should be some position, according to the correlation to move the focus,
Such as: xname containing are examples of Entry, the xname. Index (event. The widget) whether can obtain the index value

If possible just give it a try, hope to useful,

Can solved, it is good to know which object is done, I is to use the index to calculate the index value, then the addition and subtraction, switch to should go to the Entry, method may be a bit stupid, but the function implementation
  • Related