GUI: Moving between input fields

Hi,

I’m trying to figure out how to move between input fields (DirectEntry). I’ve got code that works, but I don’t know if it is the best way to do this. I’ve been combining and modifying the networking samples and HelloWorld (with the walking panda).

This code only works for enter, not for tab.

Here is where I create my login frame:

if (login == '') or (password == ''):
    parentFrame = True
    frame = DirectFrame(relief = DGG.RAISED, borderWidth = (0.05,0.05), frameSize = (-1,1,-1,1), frameColor=(.3,.2,.1,.5))
    x = 0;
    z = 0;
    frame.setPos(x,0,z)
    #frame.reparentTo(render2d)
    frame.setScale(0.5,0.5,0.5)
    if (login == ""):
        loginFocus=1
        passwordFocus=0
    else:
        loginFocus = 0
        passwordFocus = 1
    label = DirectLabel(parent =frame,text="Login to a server", scale = .1,pos = (-.5,0,.8), relief = DGG.RIDGE)
    #serverLabel = DirectLabel(parent =frame,text="Server", scale = .1,pos = (-.8,0,.5), relief = DGG.RIDGE)
    #serverText = DirectEntry( parent = frame, pos = (-.55,0,.5), text = "", scale = .1,initialText = server, numLines = 1, relief = DGG.GROOVE)
    loginLabel = DirectLabel(parent =frame,text="Login", scale = .1,pos = (-.8,0,.25), relief = DGG.RIDGE)
    loginText = DirectEntry( parent = frame, focus = loginFocus, pos = (-.55,0,.25), text = "", scale = .1,initialText = login, numLines = 1, relief = DGG.GROOVE, command = nextLoginField)
    passwordLabel = DirectLabel(parent =frame,text="Password", scale = .1,pos = (-.8,0,.0), relief = DGG.RIDGE)
    passwordText = DirectEntry( parent = frame, focus = passwordFocus, pos = (-.55,0,.0), text = "", scale = .1,initialText = password, obscured = 1, numLines = 1, relief = DGG.GROOVE, command = nextLoginField)
    DirectButton( parent = frame, pos = (.8,0, -.8), text = "Exit", scale = .1, command = myExit)
    DirectButton( parent = frame, pos = (-.8,0, -.8), text = "Login", scale = .1, command = loginFunc)
else:
    sendLogin(login, password)

And the frame calls nextLoginField when enter is hit.

def nextLoginField(self):
    if (loginText.get() == ""):
        loginText['focus']=1
    elif (passwordText.get() == ""):
        passwordText['focus']=1
    else:
        loginFunc()

Any comments or critiques are appreciated.

Better code is really appreciated.

Thanks,
Brian

Would it make more sense to use a tab? Thats what most people are accustomed to when using GUI.

In TreeGUI, I have also implements this tabing behavior. In TreeGUI you can tab between any widgets that are marked as control=True.

Could you not just have a task in the background looking for tab (or enter) that switches between a grobal list that you update depending on whats showing (aka set control = #)?

(Not sure if you did it that way treeform.) Thats how I was going to do it once I get that far.