Join Club ShowMeDo to Learn Python!

This series is a part of Club ShowMeDo. Click to learn why you should join our club with a simple monthly subscription.

  • We teach Python and all the cool modules
  • Topics include beginner Python, GUIs, Web and Desktop Apps
  • Long, specially crafted video tutorials just for you
  • Club video tutorials extend our normal Free content
  • Save your time - we've done the research for you
  • Keep your skills up-to-date
  • Learn at your own pace, everything you need is shown to you
  • Over 12 hours of archived material are waiting for you in the club

Name: [002] Ian Ozsvald
Member: 109 months
Authored: 181 videos
Description: I am the co-founder of ShowMeDo (see http://showmedo.com/about), author of `The Screencasting Handbook <http://thescreencastinghandbook.com>`_ and the founder of the professional screencast production company `ProCasts <http://procasts.co.uk>`_: .. image:: http://procasts.co.uk/media/procasts_sma ...

Solution: The working Yes/No control and EnterBox [ID:248] (7/17)

in series: Python 101 - easygui and csv

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

Here we have the working solution to the exercise from the previous episode. See my answer for talking to the user and writing some more logic.

Created May 2007, running time 2 minutes

import easygui # DONE the TODO for the import statement

# use easygui's enterbox to ask for the name from the user
name=easygui.enterbox("Please enter your name")

# use easygui's yes/no box to ask a Yes/No question
yesNo = easygui.ynbox(message = "Is "+name+" your name?")

# if "Yes" then we print the name back out
# with easygui a 'Yes' answer is represented as an Integer 1
# which is equivalent to True for Boolean logic
if yesNo == 1: # if 1 then this statement becomes True
    print "Yes "+name+" is your name"
    
# if you press No then print another message
# TIP Just as 1 is True, a 0 represents False
# so you can copy the section of code above and make
# one logic change and rewrite the print message
if yesNo == 0:
    print "No " + name + " is not your name you silly-billy!"

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 324 (since July 30th)
  • Plays in last week: 0
  • Published: 91 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>








All comments excluding tick-boxed quick-comments

Is it proper to use elif on the end? as such:

elif yesNo == 0:

Or is that a bad coding habit within PY?


THANK YOU SOOOOOOOO VERY MUCH!!! I THINK I FINALLY GET IT. JASE...


yep, same here. had to use the new "msg" instead of "message" on the yesNo line.

great tutorial so far, Ian. i discovered this site via the Ubuntu UK podcast. you seem to be the rare person who knows how to program *and* how to teach. not many have this combination of skills. glad to be here.

takayuki


worked well for me

you may cover this in the future videos, however, what about using else within if statements, saves time and code

if yesNo == 1: # if 1 then this statement becomes True

print "Yes "+name+" is your name"

else:

print "No, "+name+" is not your name, you silly-billy!"

still enjoying the CBT though.

keep it up


Possibly the author of easygui has changed the api? Thanks for the fix, certainly 'message' used to be the right way to do it.

Cheers,

Ian.


the supplied source code:

# use easygui's yes/no box to ask a Yes/No question

yesNo = easygui.ynbox(message = "Is "+name+" your name?")

this didn't work for me. The Easygui reference for ynbox:

ynbox(msg='Shall I continue?', title=' ', choices=('Yes', 'No'), image=None)

I changed message to msg and everything's working.


Review of Solution: The working Yes/No control and EnterBox

The exercise format is great. I did find that if I use message="Is ..." that I got the following

an unexpected keyword argument 'message'. I left out message= and it worked great.


Work fine for me, I also did a variance by using this line :

easygui.msgbox(message='So '+name+' is your name', title='Your name', buttonMessage='OK')

in order to get a message box at the end.


Hi Ryan, it is great to hear that the challenges and GUI components are useful to you.

Ian.


Yeah, nice overview of the Y/N and EnterBox. I can see where this is going, very interactive use of the more advanced python functionality! Excellent video.


Nice quick overview of the Enter Box/ Yes/NO box using easygui. These are two of the most common dialogs used when designing GUI's so this basic overview is necessary.


Yes, that was a bug with our source-code tab :-( It is fixed now, though every entry has to have a leading blank line (which doesn't affect the Python at all).

This is the first time we're using the new Source tab, it does look rather pretty don't you think?

Ian.


The source code above has leading spaces on line number 1 (wrongly, i think); the source code in the video not. maybe some mixup at the upload of the file ?


Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Ian

Content

Feedback

Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.

feedback@showmedo.com