[Tutor] Prompting and graphics

Andy W toodles@yifan.net
Sun, 16 Dec 2001 14:30:54 +0800

Hi Mike,

> I've got a couple of questions.  First one has to do with prompting a user
> for data and reading it in, i'm from the C++ world and used to using cin
> and cout statements.

You can use either of two functions (there might be other more obscure


They work essentially the same, but "input" evaluates the data read, whereas
"raw_input" does not. This can be dangerous if your program is open to
malicious users, who could (the most frequently used example i've seen) open
a file for writing, thus truncating it. (by supplying the input prompt with

Here's how raw_input works:

>>> x=raw_input('!> ')
!> 123
>>> x

Following on with "input"...

>>> input('eval: ')
eval: x

(Of course I could have put that into a variable, I just wanted to show the
evaluation part)

> Second, i've heard that I can graphically display some of my data.  Is
> there a seperate module I have to import?

There's a number of GUIs for Python. You will need to import a separate
module (and in non-Tkinter cases, download too).
Tkinter is the official Python GUI, but there are others such as, one which
I quite like, wxPython.

Tkinter resources:


> Thanks,
> Mike


> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor