Problem with DirectEntry

Hello am getting an error when i try to read the text from a DirectEntry by using the Get command as show below. When i try to use the command function (by pressing enter key), i successfully get the value. But i dont want the player to press enter key. Instead he should click on a button. Any one can help me please?

The error i get is this:

File "C:\Panda3D-1.5.4\direct\src\gui\DirectButton.py", line 103, in commandFunc
    apply(self['command'], self['extraArgs'])
File "C:\Shared\CampusWars\NewGameMenu.py", line 33, in setCreate
    self.gname =self.t1.get()
File "C:\Panda3D-1.5.4\direct\src\gui\DirectEntry.py", line 280, in get
    wantWide = self.unicodeText or self.guiItem.isWtext()
AttributeError: 'DirectEntry' object has no attribute 'guiItem'

Note: T1 is a directEntry

I think you are calling get() after your DirectEntry has been destroyed.

David

Hi Thanks for replying…No the DirectEntry is still there :cry:

Check out the full code on that module


import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *

from pandac.PandaModules import *
import GameSettings
from Button import *

class NewGameMenu():
  def initScreen(self,GameName):
    self.gname=GameName
    GameSettings.backImage.setImage(GameSettings.newImage)
    self.maps = loader.loadModel(GameSettings.spath+'NewGame/buttons_new.egg')
    self.myFrame = DirectFrame(scale=1.5,pos=(0.78,0,-1.7))
    #add button
    self.t1 = DirectEntry(text = "" ,
                          relief=None,
                          pos = (-0.7,0,1.125),
                          scale=0.03,
                          parent=self.myFrame, 
                          text_fg=(1,1,1,1), 
                          initialText=self.gname, 
                          numLines = 1,
                          focus=1,
                          focusInCommand=self.clearText,
                          command=self.setText)

    self.b1 = Button('cancel',(-0.55,0,1.05),self.maps,self.myFrame,self.backScreen ,[])
    self.b2 = Button('create',(-0.37,0,1.05),self.maps,self.myFrame,self.setCreate ,[])
      
  def setCreate(self):
    self.destroyAll()
    self.gname =self.t1.guiItem.get()
    GameSettings.createMenu.initScreen(self.gname)
    
  def backScreen(self):
    #Move to previous Screen
    self.destroyAll()
    GameSettings.mainMenu.initScreen()

  def setText(self,textEntered):
      self.gname=textEntered
      self.setCreate()

  def clearText(self):
      self.t1.enterText('')

  def destroyAll(self):
    self.maps.removeNode()
    self.b1.destroy()
    self.b2.destroy()
    self.t1.destroy()
    self.myFrame.destroy()

Oooops, thanks that was the solution… Sorry for that previous post… Thanks again…it was so silly mistake…

What do you mean? You have this code:

    self.destroyAll()
    self.gname =self.t1.guiItem.get() 

That is, you are querying self.t1 immediately after you have called self.destroyAll(). Within self.destroyAll(), you are calling (among other things) self.t1.destroy().

It sure does seem like self.t1 will have been destroyed by the time you call get on it.

Incidentally, aside from the destruction issue, you need to call self.t1.get(), not self.t1.guitItem.get().

David

You are absolutely right…it was a very silly mistake…Thanks sooo much…