Python
  Home arrow Python arrow Page 4 - Mobile Programming in Python using PyS...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Mobile Programming in Python using PyS60: UI Controls
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-27

    Table of Contents:
  • Mobile Programming in Python using PyS60: UI Controls
  • UI Controls: Query and Notes
  • The Note Control
  • PyS60 in Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Mobile Programming in Python using PyS60: UI Controls - PyS60 in Real World
    (Page 4 of 4 )

    Let's see how these controls can be used within an application. The application that's going to be developed is a simple guessing game. It will perform the following tasks:

    1. Choose a random number. 
    2. Ask the user to enter his or her guess.
    3. Compare and show the result.
    4. Ask if he or she will like to continue.

    So let's start. First the imports:

    from appuifw import *

    As you already know, the above statement imports all the classes within the appuifw module. Next, the application has to choose a random number. However, since this will be a repeating process until the user chooses to stop, choosing the random number will be within a loop. The loop will terminate only when the user says he or she would like to stop. The code is as follows:

    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    The loop will continue until continue_guess becomes false. Next, the application needs to accept the user’s guess. To accept the value, the query function will be used. The message will be “Enter your guess,” the type will be number (since decimals will not be allowed), and no initial value will be displayed. The value will be saved in user_guess variable. Here is the code:

    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    user_guess=query(u”Enter your guess”, ‘number’)

    Next comes the comparison and displaying the result functionality. First, the user_guess will be checked for validity (i.e. if the user clicked cancel, it would be null). If it is not null, then it will be compared with the guess_no, and the appropriate number will be displayed. If the user pressed cancel, a “You opted out” will be shown and the continue_guess will be set to false. Here is the code:


    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    user_guess=query(u”Enter your guess”, ‘number’)

    if user_guess is Null:

    note(u”You have opted out”)

    continue_guess=false

    elif user_guess<guess_no:

    note(u”Your guess is lesser than the goal”)

    elif user_guess>guess_no:

    note(u”Your guess is higher than the goal”)

    else:

    note(u”Congrats for excellent guess”)


    Next comes the code that asks the user whether or not to continue. The query box is shown to the user with “Enter Y to continue and N quit.” If Y is entered, the loop is continued, otherwise the application is exited.


    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    user_guess=query(u”Enter your guess”, ‘number’)

    if user_guess is Null:

    note(u”You have opted out”)

    continue_guess=false

    elif user_guess<guess_no:

    note(u”Your guess is lesser than the goal”)

    elif user_guess>guess_no:

    note(u”Your guess is higher than the goal”)

    else:

    note(u”Congrats for excellent guess”)


    user_choice=query(u”Enter Y to continue or N to quit”)

     

    if user_choice is Null or user_choice==’N’:

    continue_guess=false

    else:

    continue_guess=true


    That completes the application. In this discussion, the focus was on simple UI controls. The next part will discuss complex UI controls, such as forms. Till then…


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In this discussion I have explained about the basic UI controls supported by...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway