I am constructing some sort of a status bar which allows the user to update their status while in a social network. It consists of an entry field and a 'update' button beside it.
What I hope to do is upon activation of the button 'update' the contents in status entry box should dissappear and reappear in the text box below it.
However I can not get the information entered into the status entry box with status.get()

Here is what I have:

from Tkinter import *

def status_on(status1, text1, statusentry):
    text1.insert(INSERT, status1) #the text only displays the part 'name is: '
    statusentry.delete(0, END)

def status_off(text1):
    text1.delete(1.0, END)

if __name__=='__main__':
    window = Tk()
    frame = Frame(window)
    frame.grid(rowspan=100, columnspan=100)

    short_status_label = name + 'is: ' #the label on status bar
    statuslabel = Label(frame, text=short_status_label)
    statuslabel.grid(row=14, column=3)
    statusentry = Entry(frame, textvariable=status)
    statusentry.grid(row=14, column=4)
    status1 = status.get()# status1 should now contain the value of status but it doesn't
    print status1              # nothing is printed
    status1 = name + ' is'  + ' ' + status1

    text1 = Text(frame, height=1, width=25)#the text box that is supposed to display the status info
    text1.grid(row=15, column=3) 
    status_off(text1)

    update = Button(frame, text='Update', command=\
                    lambda: status_on(status1, text1, statusentry))

     update.grid(row=14, column=6)

And help would be greately appreciated!

Sometime it pays to write a short test code:

# set up a short test with Tkinter's
# Label, Entry, Button and Text widgets
# check some of the interactions

from Tkinter import *

def update():
    data = entry.get()
    # clear any old text
    text.delete(1.0, END)
    text.insert(INSERT, data)
    # clear the entry
    entry.delete(0, END)


root = Tk()

# for testing
name = "Franko"
s = name + " is:"

# create needed widgets
label = Label(root, text=s)
entry = Entry(root, width=25)
button = Button(root, text="Update", command=update)
text = Text(root, width=25, height=1)

# place the widgets in a grid
label.grid(row=1, column=1)
entry.grid(row=1, column=2)
button.grid(row=1, column=3)
text.grid(row=2, column=1)

# put the cursor into entry field
entry.focus()

root.mainloop()

Please put your code between code tags (the "#" icon) as no one will be able to run your program without proper indents. Generally, you use a control variable, in your case a string control variable, and the ".set " and ".get" methods to change the text or get the text. Here is a link to New Mexico Tech's page http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html From that site "For example, you could link an Entry widget to a Label widget so that when the user changes the text in the entry and presses the Enter key, the label is automatically updated to show that same text." This is their example, using different widgets than you, but the idea is the same

self.spamVar = StringVar()
self.spamCB  = Checkbutton ( self, text="Spam?",
        variable=self.spamVar, onvalue="yes", offvalue="no" )

Note the "variable=" which defines the variable that contains the text/data. Write a simple example with one widget and update the text every time you click a button. Then, you should be able to do the rest.

commented: good ref +11

Thanks for the prompt reply, they were very helpful ^)^

I noticed that in sneekula's post, that you didn't use the line if __name__=='__main__': before root = Tk() So is that the reason the widgets Text and Entry were not passed as arguments into update?
Is there a reason why that is so? I thought text and entry are global variables.

You use
if __name__=='__main__':
only if you want to test your code as a standalone module.

I have come across another problem in building this same GUI, i.e. the status bar that updates member information.

However whenever I run the program I get the error message: AttributeError: Button instance has no __call__ method

I read it so many times and still can't see what's wrong with it, everythings seems to be where it should be...

def update(status_heading):
    '''This will update  the text box with the value of status'''
    #clearing what was in the text field before
    text1.delete(1.0, END)
    status = statusentry.get()
    message = status_heading + status
    text1.insert(INSERT, message)
    #clearing what was in the entry box
    statusentry.delete(0, END)

window = Tk()
frame = Frame(window)
frame.grid(rowspan=100, columnspan=100)

status_heading = name + ' is ' #the label on status bar

heading_status_label = Label(frame, text=status_heading, \ bg='turquoise',font=('Garamond', 12))
heading_status_label.grid(row=14, column=3)
        
statusentry = Entry(frame, width=25)
statusentry.grid(row=14, column=4)
        
text1 = Text(frame, height = 1, width = 25)
text1.grid(row=15, column=4)

update = Button(frame, text='Update', command=lambda:update(status_heading))   # this is where the error occured
update.grid(row=14, column=6)              

window.mainloop()

One of your problems is that you named the button and the function the same! Name your button "button_update" or something.

Other problems are the '\' in Label and that name is not assigned a value.

commented: nice catch +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.