User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 427,097 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,317 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 391 | Replies: 1
Reply
Join Date: May 2008
Posts: 18
Reputation: MikeyFTW is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
MikeyFTW MikeyFTW is offline Offline
Newbie Poster

Simple graphics in python GUI - Tkinter

  #1  
Jul 25th, 2008
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...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Location: Milano, Italy
Posts: 16
Reputation: TheOneElectroni is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
TheOneElectroni's Avatar
TheOneElectroni TheOneElectroni is offline Offline
Newbie Poster

Re: Simple graphics in python GUI - Tkinter

  #2  
Jul 25th, 2008
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:

  1. #here you import the module
  2. from PIL import Image, ImageTk
  3. #here you load the image you are going to use
  4. Logo_IMG = Image.open("C:\Python25\..........\Logo.png")
  5. #here you use Photoimage to assign the image to ImageTk
  6. Logo_TK = ImageTk.PhotoImage(Logo_IMG)
  7. #here you create a simple canvas widget -I assume you have already a frame to put it
  8. Canv_logo = Canvas(your_canvas_frame, width=50, height=50, bg="white", bd=0)
  9. #here you show the image in the canvas
  10. Canv_logo.create_image(36, 36, image=Logo_TK)
  11. Canv_logo.grid()
  12. #here you reference at the image again -without this you won't see the image-
  13. 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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 5:33 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC