2.3. Writing a Program in Python for S60

Sidebar 2.1. First PyS60 program

We write a simple program consisting of three lines of code as our first real example. It should do the following:

  1. Display a text input field on the screen; the instruction in the text field should say 'Type your name' (see Figure 2.11(a)).

  2. Display a popup note stating 'Greetings from:' followed by whatever the user typed into the text input field (see Figure 2.11(b)).

Figure 2-11. Our first Python script example: (a) a text input field and (b) a popup note

The code to do this is as follows:

import appuifw
name = appuifw.query(u"Type your name:", "text")
appuifw.note(u"Hello world! Greetings from: " + str(name), "info")

In the first line of code, we import the appuifw module, which handles user interface elements such as text input fields and popup notes.

In the second line of code, we create a single-field dialog (Figure 2.11(a)) using the query() function of the appuifw module with two parameters: label and type. For the first parameter, label, we put the text u "Type your name:". The u is required because the phone understands only text declared as Unicode and the quotation marks are needed because the label parameter must be given as a string. As the second parameter, type, we put "text", to declare the input field as a text dialog. Other possible types are "number", "date", "time", "query" and "

Get Mobile Python: Rapid Prototyping of Applications on the Mobile Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.