What am I doing wrong in this simple tkinter example?

Y

Yves S. Garret

Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to
become more acquainted with the language. However, when I got to page 304 and
did my first example:

http://bin.cakephp.org/view/1107093008

And this is the error that I'm getting:

http://bin.cakephp.org/view/399711843

This is the code that came with the book:

http://bin.cakephp.org/view/514822432


What I don't understand is, why am I getting that error? I've done diff -w
and the code looks for the most part the same. What am I doing wrong when I
put the application together?
 
C

Chris Angelico

Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to
become more acquainted with the language. However, when I got to page 304 and
did my first example:

http://bin.cakephp.org/view/1107093008

And this is the error that I'm getting:

http://bin.cakephp.org/view/399711843

This is the code that came with the book:

http://bin.cakephp.org/view/514822432


What I don't understand is, why am I getting that error? I've done diff -w
and the code looks for the most part the same. What am I doing wrong when I
put the application together?

self.secret_txt.delete(0.0, END)
self.secret_txt.delete(0.0, message)

Is the second one supposed to be adding text? I'm not familiar with
tkinter but that's the line with the error, and it looks a little odd.

ChrisA
 
M

Mitya Sirenef

Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to
become more acquainted with the language. However, when I got to page 304 and
did my first example:

http://bin.cakephp.org/view/1107093008

And this is the error that I'm getting:

http://bin.cakephp.org/view/399711843

This is the code that came with the book:

http://bin.cakephp.org/view/514822432


What I don't understand is, why am I getting that error? I've done diff -w
and the code looks for the most part the same. What am I doing wrong when I
put the application together?


The error is that indexes are supposed to be integers, instead you have
a text string:

"That's not the correct password, so I can't s hare the secret with you."


-m
 
Y

Yves S. Garret

self.secret_txt.delete(0.0, END)

self.secret_txt.delete(0.0, message)



Is the second one supposed to be adding text? I'm not familiar with

tkinter but that's the line with the error, and it looks a little odd.



ChrisA

Yes, the second line is supposed to add the text.
 
Y

Yves S. Garret

self.secret_txt.delete(0.0, END)

self.secret_txt.delete(0.0, message)



Is the second one supposed to be adding text? I'm not familiar with

tkinter but that's the line with the error, and it looks a little odd.



ChrisA

Yes, the second line is supposed to add the text.
 
Y

Yves S. Garret

304 and


diff -w


when I






The error is that indexes are supposed to be integers, instead you have

a text string:



"That's not the correct password, so I can't s hare the secret with you."





-m





--

Lark's Tongue Guide to Python: http://lightbird.net/larks/



The existence of any evil anywhere at any time absolutely ruins a total

optimism. George Santayana

*shrug*

In the example that I have posted from the book it works just fine. I also used
this batch file to help me along.

longevity.py
pause

Hence the question mark over my head at the moment :) .
 
Y

Yves S. Garret

304 and


diff -w


when I






The error is that indexes are supposed to be integers, instead you have

a text string:



"That's not the correct password, so I can't s hare the secret with you."





-m





--

Lark's Tongue Guide to Python: http://lightbird.net/larks/



The existence of any evil anywhere at any time absolutely ruins a total

optimism. George Santayana

*shrug*

In the example that I have posted from the book it works just fine. I also used
this batch file to help me along.

longevity.py
pause

Hence the question mark over my head at the moment :) .
 
C

Chris Angelico

In the example that I have posted from the book it works just fine.

Yep, I just checked the book's version again and the difference is
clear. Check out the two lines I quoted in my previous post, and look
at the corresponding two lines in the book's version. You should see
the difference. :)

By the way, I like the choice of secret. It lends itself well to a
discussion of recursion - how do you live to 99? Live to 98, then be
careful. Etcetera. You need just one special case: How do you live to
1? Be born, then be careful. And there you have it, a perfect problem
for defining recursion vs iteration, as both can do the job!

ChrisA
 
Y

Yves S. Garret

Yep, I just checked the book's version again and the difference is

clear. Check out the two lines I quoted in my previous post, and look

at the corresponding two lines in the book's version. You should see

the difference. :)



By the way, I like the choice of secret. It lends itself well to a

discussion of recursion - how do you live to 99? Live to 98, then be

careful. Etcetera. You need just one special case: How do you live to

1? Be born, then be careful. And there you have it, a perfect problem

for defining recursion vs iteration, as both can do the job!



ChrisA

*facepalm*

Yep, I see it :) . Thanks for your help.
 
Y

Yves S. Garret

Yep, I just checked the book's version again and the difference is

clear. Check out the two lines I quoted in my previous post, and look

at the corresponding two lines in the book's version. You should see

the difference. :)



By the way, I like the choice of secret. It lends itself well to a

discussion of recursion - how do you live to 99? Live to 98, then be

careful. Etcetera. You need just one special case: How do you live to

1? Be born, then be careful. And there you have it, a perfect problem

for defining recursion vs iteration, as both can do the job!



ChrisA

*facepalm*

Yep, I see it :) . Thanks for your help.
 
C

Chris Angelico

*facepalm*

Yep, I see it :) . Thanks for your help.

Glad to be of service. Welcome to a life of programming, where the
palm meets the face on a regular basis... more frequently if you use
Microsoft Windows, tar, non-eight-bit-clean transmission methods, or
Adobe products, and extremely common as soon as you take over someone
else's code [1], but inevitable even without these stimuli. :)

Have fun!

[1] http://www.dilbert.com/strips/comic/2013-02-24/

ChrisA
 
M

Mitya Sirenef

*shrug*

In the example that I have posted from the book it works just fine. I also used
this batch file to help me along.

longevity.py
pause

Hence the question mark over my head at the moment :) .

You are giving a message to the delete call, but delete call
needs an integer to work. In the book, it's not a delete call
but an insert call that's why it works there.

-m
 
N

Neil Cerutti

*facepalm*

Yep, I see it :) . Thanks for your help.

Glad to be of service. Welcome to a life of programming, where
the palm meets the face on a regular basis... more frequently
if you use Microsoft Windows, tar, non-eight-bit-clean
transmission methods, or Adobe products, and extremely common
as soon as you take over someone else's code [1], but
inevitable even without these stimuli. :)

A pretty funny example of this is depicted in the fine film
Office Space.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top