Start New Discussion within our Software Development Community

Can anyone help me in graphics in python GUI using Tkinter toolkit...can anyone give me a code that can implement simple images onto the canvas of a GUI program, i know i have to use bmp. or gif. images which is fine because i got that.

Thanks...

I use PIL (Python Imaging Library) module which is more flexible with graphics usage in python and let you use formats different from say gif.
So I advise you first to install PIL from here http://www.pythonware.com/products/pil/
Then a very simple example which focus only on the load image and canvas part:

#here you import the module
from PIL import Image, ImageTk
#here you load the image you are going to use
Logo_IMG = Image.open("C:\Python25\..........\Logo.png")
#here you use Photoimage to assign the image to ImageTk
Logo_TK = ImageTk.PhotoImage(Logo_IMG)
#here you create a simple canvas widget -I assume you have already a frame to put it
Canv_logo = Canvas(your_canvas_frame, width=50, height=50, bg="white", bd=0)
#here you show the image in the canvas
Canv_logo.create_image(36, 36, image=Logo_TK)
Canv_logo.grid()
#here you reference at the image again -without this you won't see the image-
Canv_logo.image = Logo_TK

I hope this can be of help.
You can refer also to these guides
http://www.pythonware.com/library/tkinter/introduction/
http://infohost.nmt.edu/tcc/help/pubs/tkinter/

By the way I've noticed that in windows the image is bordered by default Tk gray. Even if I try to set frame/widget bg and bd to white the gray border stays there and grey anyway... Any suggestion for solving this issue?

Gab

This article has been dead for over six months. Start a new discussion instead.