Blender 2.49 GUI: How to store text inputed from a "Blender.Draw.String" Textbox

Hello Everyone.

I am new to Blender GUI, & the older version is tough because there is no code_Completion on the Console which I used to learn libraries in the latest Blenders 2.5~. But my problem is that my Mentor has asked me to create a clean WIndow rather than the Panels that are under existing Windows in the so called Blender 2.5~

I have used this to create my Textboxes. I will post the whole code after this:

textInput = Blender.Draw.Create(strInput)
textInput = Blender.Draw.String("Str: ",3,100,150,100,20,textInput.val,20,“its tooltip”)
strInput = textInput.val

#This is the Code#


import bpy
import Blender
import activeFace as faceOperations

strInput = "Empty"


#Create the GUI Widgets
def drawMe():            #Not reserved
    # Toggle(name,event,x,y,width,height,default,"popupTooltip")
    Blender.Draw.Toggle("ClearLocation",1, 10,20, 100,20,0,"Tooltip")
    Blender.Draw.Toggle("TransLate",2,20,100, 100,20,0,"Tooltip2")
    #Create LabelBox
    #Create inputs
    global textInput,strInput
    #textInput = Blender.Draw.Create(strInput)
    intInput = Blender.Draw.Create(0)

    #Create TextBox
    print "Before",strInput
    textInput= Blender.Draw.String("Str: ",3,100,150,100,20,strInput,20,"its tooltip")
    strInput = textInput.val
    print "After",textInput,strInput
def event(evt,val):
    if evt == Blender.Draw.ESCKEY:


My Text dissappears from the Textbox when I move the cursor away or click a button. I need to store a String from User Input
It appears as if Blender Runs the whole scripts from scratch everytime the GUI refreshes(redraws)

I tried making a global variable " strInput" to keep the String beyond the function " drawMe()"

Don’t you need to define strInput as global within the def? Otherwise python makes a local copy with the same name, which is an empty string.

def DrawMe ():
    global strInput

I have done that look under:
#Create inputs

I found the Solution after ‘hacking’ it::smiley: I only had to declare Blender.Draw.Create type variables at a Global Scope.

myString = Blender.Draw.Create("myText")

def draw():global myString

myString = Blender.Draw.String(""+": ",2,50,50, 300,20,\
       myString.val,20," tooltip for this widget")

I appears that Blender calls the draw() functions recursively during runtime.

#Above: !BPY identifies this script as a Blender script.    

import bpy
from Blender import Draw,Window

import Blender

obj = Blender.Scene.GetCurrent().getActiveObject()
n = len(
listWidgets = []

def myGui():
    global listWidgets,n
    #Make Global variables to store textbox values
    for i in range(n):
        listWidgets.append( Draw.Create("")  )
    #Create the Textboxes    
    y = 100
    for i in range(n):
        y = 20
        y *= i
        listWidgets[i] = Draw.String("Text"+str(i)+": ",2,50,y, 300,20,\
        listWidgets[i].val,20," tooltip for "+str(i) )

    #Place it at the center of the Window
    xbtn = Window.GetAreaSize()[0]/2
    ybtn = Window.GetAreaSize()[1]/2
    #Create the Buttons    
      Draw.PushButton("PrintIt",1,xbtn,ybtn, 100,20,"All Textboxes & values")
    Draw.PushButton("Refresh",3,xbtn,ybtn-20, 100,20,"All Textboxes & values")
    Draw.PushButton("Exit",10,xbtn*2-100,0, 100,20,"Exit the Program")

def keyboardEvents(event,val):
    global n,listWidgets
    if event == Draw.ESCKEY:
        print "There must be %d textboxes"%(n)
def buttons(event):
    global n,listWidgets
    if event == 1:
        for i in range(n):
            print "Textbox[%d]: %s" % (i,str(listWidgets[i]))
    if event == 2:
        print "Event 2"
    if event == 3:
        Draw.Register(None, None,None)
        Draw.Register(myGui, keyboardEvents, buttons)  
    if event == 10:
        print "Exiting......"

#Reserved Structure for Blender GUI. Functions for windowing
#Register the 3 required functions (draw, event, button)
Draw.Register(myGui, keyboardEvents, buttons)