The Artima Developer Community
Sponsored Link

Python Answers Forum
my_button["command"] problem

2 replies on 1 page. Most recent reply: Aug 25, 2004 10:25 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

my_button["command"] problem Posted: Aug 24, 2004 7:49 PM
Reply to this message Reply
Advertisement
This is some Python code I've been trying to
deal with, its using the Tkinter resources.

I'm trying to figure out why the string test
is constantly returning an empty string.

Even when I type something in the entry and
press the Connect button, nothing is happening.

Actually I do know whats happening but can't
figure out how to resolve it. Connect is being
called before I even press the Connect button.
Why is this? I noticed this by the fact that as
soon as I start my application, the line
print "connecting" is being executed. Why is
this.

def connect():
global test
test = str(field1.get())
print "connecting..."
print test

root = Tk()
root.title("My Application")

field1 = Entry(root)
field1["width"] = 80
field1["fg"] = "navy"
field1.pack({"side": "top"})

CONNECT = Button(root)
CONNECT["text"] = "Connect" # connect should
# be called here
CONNECT["fg"] = "navy"
CONNECT["command"] = connect()
CONNECT.pack({"side": "right"})

root.mainloop()



Thanks in advance.

Spike


Andy

Posts: 28
Nickname: adn
Registered: Jul, 2004

Re: my_button["command"] problem Posted: Aug 25, 2004 4:42 AM
Reply to this message Reply
CONNECT["command"] = connect()
Sets the command to the value of connect() rather than the function connect.

Do:
CONNECT["command"] = connect

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: my_button["command"] problem Posted: Aug 25, 2004 10:25 AM
Reply to this message Reply
That was a great help, I had tried just about everything.
Thanks a mill.

Spike

Flat View: This topic has 2 replies on 1 page
Topic: adding while loop outputs? Previous Topic   Next Topic Topic: where should i start?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use