PDA

View Full Version : Text Box


malmct
08-04-2010, 08:23 AM
I'm trying to use a textbox for text entry. However, whenever I call .get() on the text box, it only returns an empty string, regardless of whats in the box.


class makeMenu:
def __init__(self):

#Menu Generation
self.treadMenu=vizmenu.add()
self.command=self.treadMenu.add("Commands")
self.speed=self.treadMenu.add("Speed")

#Command Box

self.go=self.command.add(viz.BUTTON_LABEL,"GO")
self.stop=self.command.add(viz.BUTTON_LABEL,"STOP")


#Speed Box
self.lspeed=self.speed.add(viz.TEXTBOX, "LEFT BELT SPEED:")
self.rspeed=self.speed.add(viz.TEXTBOX, "RIGHT BELT SPEED:")

vizact.onbuttondown(trMenu.go, moveBuffer, trMenu.lspeed.get(), trMenu.rspeed.get())

def moveBuffer(lsp, rsp):
print lsp


lsp is always an empty string.

Jeff
08-06-2010, 10:02 AM
The code below works. I'll find out why the values are not passed to the callback function the way you have it and get back to you.
import viz
import vizmenu

viz.go()

class makeMenu:
def __init__(self):

#Menu Generation
self.treadMenu=vizmenu.add()
self.command=self.treadMenu.add("Commands")
self.speed=self.treadMenu.add("Speed")

#Command Box

self.go=self.command.add(viz.BUTTON_LABEL,"GO")
self.stop=self.command.add(viz.BUTTON_LABEL,"STOP")


#Speed Box
self.lspeed=self.speed.add(viz.TEXTBOX, "LEFT BELT SPEED:")
self.rspeed=self.speed.add(viz.TEXTBOX, "RIGHT BELT SPEED:")


trMenu = makeMenu()

def moveBuffer():
print 'Left Belt Speed: ',trMenu.lspeed.get()
print 'Right Belt Speed: ',trMenu.rspeed.get()

vizact.onbuttondown(trMenu.go, moveBuffer)

Jeff
08-06-2010, 01:58 PM
The code you posted works as it should. When your callback function is registered through the vizact.onbuttondown command, the values in both text boxes are empty strings. Getting the textbox values at the time of the button press should be done in the callback function itself, as in my example.

malmct
08-10-2010, 08:18 AM
That makes sense. Thank you very much.