3

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?

KevinShaffer
  • 760
  • 5
  • 14
  • 26

2 Answers2

4

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

matchew
  • 19,195
  • 5
  • 44
  • 48
  • also, where would the image have to be stored? The same directory as the file? – KevinShaffer Nov 28 '12 at 04:44
  • @KevinShaffer you can store the image anywhere as long as you use the correct path, `im = Image.open(r"\some\dir\to\image\bear.png")`. – John Nov 28 '12 at 07:03
2

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.

i love stackoverflow
  • 1,555
  • 3
  • 12
  • 24