Focus on DirectEntry --> solved

Hi,

I got a little problem with focus on directEntry.
I wish with tab character, to switch from a directEntry to another one.
for that, I use myDirectEntryObject.setFocus(), but it didn’t go on the target directEntryObject. Is there a trick?

Are you sure you call setFocus() on the next entry ?

class menuconnect(DirectObject):
  def __init__(self):
    self.focuson=0
    self.accept("tab", self.tab, [0])
    self.background=DirectFrame(scale=6,text_fg=(0,0,0,1),relief=2,frameColor=(0.25,0,0.78,0.7))
    self.user = DirectEntry(text = "" ,scale=.05,command=setText,initialText="", numLines = 1,focus=1,relief=2,frameColor=(0.25,0.17,0.75,0.5))
    self.pwd = DirectEntry(text = "" ,scale=.05,command=setText,initialText="", numLines = 1,focus=0,relief=2,frameColor=(0.25,0.17,0.75,0.5),pos=(0,0,-0.2))
    self.btn=DirectButton(text= ("Connect"),command=self.connect,scale=0.08,pos=(0.4,0,-0.4))
    self.imgbck=OnscreenImage(parent=render2d,image="background/backmenuconnect.jpg")

        
  def tab(self,arg):
    if(self.focuson==0):
      self.pwd.setFocus()
      self.focuson=1
    else:
      self.user.setFocus()
      self.focuson=0
    
 

I hope so :stuck_out_tongue:
I use a variable to store on which entry there is the focus, cause I didn’t find a method like hasFocus().

Don’t use self.pwd.setFocus(); that method isn’t meant to be called directly. Instead, use self.pwd[‘focus’] = True.

David

Right. It Works!
I imagine it is the same way for all other attributes.
I think I come from C++ world, and I am focus on class/method. lol.

Thanks!