Username & Password Fields

Hey,

Just having a problem, i need 2 entry fields for username and password, when you hit the directbutton, it submits those fields and runs one command.

How can i do this? Ive got it working for onw field but thats it and its a direct entry.

  • Chris

To make a password field, set obscured=True in the DirectEntry constructor.

In the DirectButton that submits the form, specify as “command” a function that reads out the entries with entry.get() and does whatever you want with it.

can u show me an example?

i dont have a stand-alone-script which you can run right away.
but here’s a snippset from the login-screen of an old game of mine which should be pretty much the thing you’r looking for.

btw… never mind that there is a frame and a bg-frame. the frame is my topmost gui-element so i can delete all guy’s with one destroy() call. the bg.frame contained the menu-background image.

def loginScreen(self):

    self.frame = DirectFrame(
    frameColor=(0,0,0,0),
    frameSize=(-1,1,-1,1))

    self.bgFrame = DirectFrame(
    frameColor=(0,0,0,0), 
    frameSize=(-1,1,-1,1),
    sortOrder=1)
    self.bgFrame.reparentTo(self.frame)
    
    self.unEntry = DirectEntry(initialText="Username",
    scale=0.05,
    text_scale=(1,1),
    pos=(-.56,0,-0.57),
    frameColor=(1,1,1,0.1))
    self.unEntry.reparentTo(self.frame)
    
    
    self.pwEntry = DirectEntry(
    initialText="Password",
    scale=0.05,
    text_scale=(1,1),
    pos=(-.56,0,-.71),
    frameColor=(1,1,1,0.1),
    obscured=1)
    
    self.pwEntry.reparentTo(self.frame)

    self.loginbutton = DirectButton(text = ">  Login  <",
    pos=(0.13,0,-.57),
    scale=0.06,
    command=self.login)
    
    self.loginbutton.reparentTo(self.frame)
  
  def login(self):
    print self.unEntry.get(), self.pwEntry.get()
    self.frame.destroy()