KevinShaffer
KevinShaffer

Reputation: 858

I want to get python to output a png file

I am currently trying to get a picture that I have, or even one on the web that I can link to, to output from my python code from an if statement.

Here's the code:

if c >= 50:
    print '\nYou have been mauled by a bear\n'
    # I want to output a picture of a bear here
    quit()

I have a counter for c, and if it hits 50 I want it to print out that You have been mauled by a bear, and then on the screen have a bear pop up, whether the bear image is just a file in the same folder, or if it links to a webpage that I have the bear image hosted at.

Is this possible?

Upvotes: 3

Views: 18393

Answers (2)

matchew
matchew

Reputation: 19665

There are many ways to do this, I would use image module from PIL

from PIL import Image
im = Image.open("bear.png")
im.show()

Other ways would be to use one of the following: wxWindows, pyQt, pyGTK, or Tkinter

Upvotes: 4

i love stackoverflow
i love stackoverflow

Reputation: 1685

On a Mac:

from subprocess import call
call(["open", "hi.jpg"])

This should also work on other systems if you substitute "open" with whatever program you use to open images.

Upvotes: 2

Related Questions