[Tutor] Displaying picture and Text

Alan Gauld alan.gauld at btinternet.com
Thu Nov 4 09:58:10 CET 2010


<patty at cruzio.com> wrote

> of my python program where a picture is supposed to display with a 
> few
> lines of text below it.

To do this you will need to use some kind of GUI.
The simplest option is probably  to use the Text widget in Tkinter
which can display both Images and text.

> Ideally, I would like this to stay on the screen
> for  a short  period of time (2 minutes?)

You would do that with a Timer event in Tkinter.

> import Image
>
> fhdl = Image.open("C:\Users\StarShip\PyProgs\\bbsparkle.gif")
> fhdl.show()

I've never used Image but I assume the show() method just
invokes the default viewer on the system.

> print "here is some test text test text test text"
> print "here is some more test text test text test text"
> print "here is even more of some test text test text test text"

print will always go to stdout, wherever that is defined to be..

> How do I get any picture to display on half a screen then my print 
> text
> display below that and stay on screen for 2 or 3 minutes before I 
> call
> another function that will redraw the screen anyway - it will be
> interactive text responses with the user.  Also this is a test .gif 
> file,
> I may want to just edit the source file and change this to a .jpg.

The Tkinter PhotoImage object can display jpg. I can't recall if
it does gifs. If you want to habndle many types yoyu may need to
look at using an image convertion library too.

> I don't want to change the system defaults for this, maybe for the 
> picture
> itself if that is necessary.

That should not be necessary, if you tell Python the filepath it can
load the specific file you select.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list