The Tkinter module comes with the normal Python installation. It allows you to create Python GUI programs for Windows, Linux or Unix on the Mac. In this snippet we put a GIF image (.gif) onto a form's canvas with just a few lines of code. Most of the lines are remarks to explain what is going on.
Tkinter to put a GIF Image on a Canvas (Python)
# Putting a gif image on a canvas with Tkinter
# tested with Python24 by vegaseat 25jun2005
from Tkinter import *
# create the canvas, size in pixels
canvas = Canvas(width = 300, height = 200, bg = 'yellow')
# pack the canvas into a frame/form
canvas.pack(expand = YES, fill = BOTH)
# load the .gif image file
# put in your own gif file here, may need to add full path
# like 'C:/WINDOWS/Help/Tours/WindowsMediaPlayer/Img/mplogo.gif'
gif1 = PhotoImage(file = 'DrBunsen.gif')
# put gif image on canvas
# pic's upper left corner (NW) on the canvas is at x=50 y=10
canvas.create_image(50, 10, image = gif1, anchor = NW)
# run it ...
mainloop()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
Shannon_3 0 Newbie Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
urireo561 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Ash_4 0 Newbie Poster
yas_549 0 Newbie Poster
CodeWorked 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.