[Tkinter-discuss] Python Tkinter Simple Qn

Firat Ozgul ozgulfirat at gmail.com
Thu Aug 12 14:55:04 CEST 2010


My previous code was erroneous. Therefore I edited it.

http://paste-it.net/public/u46e119/

2010/8/12 Chris Chia <chrischia82 at gmail.com>

> Hi i have the following problem with Python Tkinter.
> I switch to switch the image background (which i used Tkinter.Label with
> image arg to display on the GUI).
>
> How can I do that? the callback function which i have created doesn't seem
> to work...
> some advice?
>
> below is my code:
>
>
> import Tkinter as tk
> from PIL import Image, ImageTk
>
> root = tk.Tk()
>
> # having problem with switching the image
> def callback(event):
>     global root
>     root.panel1.pack_forget()
>     root.panel1.image = image2
>     root.panel1.pack()
>
>
> def app():
>
>     root.title('FIT 2022 Assignment 1')
>
>     # pick an image file you have .bmp .jpg .gif. .png
>     # load the file and covert it to a Tkinter image object
>     imageFile = "c:\\test1.jpg"
>     image1 = ImageTk.PhotoImage(Image.open(imageFile))
>     imageFile2 = "c:\\test2.jpg"
>     image2 = ImageTk.PhotoImage(Image.open(imageFile2))
>
>
>     # get the image size
>     w = image1.width()
>     h = image1.height()
>
>
>     # position coordinates of root 'upper left corner'
>     x = 0
>     y = 0
>
>
>     # make the root window the size of the image
>     root.geometry("%dx%d+%d+%d" % (w, h, x, y))
>
>
>     # root has no image argument, so use a label as a panel
>     panel1 = tk.Label(root, image=image1)
>     panel1.pack(side='top', fill='both', expand='yes')
>     panel1.image = image1
>     panel1.bind("<Button-1>", callback)
>
>
>     panel1.pack()
>     root.mainloop()
>
>
> app()
>
>
>
>
> --
> Regards,
> Chris
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100812/35c4c308/attachment.html>


More information about the Tkinter-discuss mailing list