[Tkinter-discuss] Frame Background

jepler@unpythonic.net jepler at unpythonic.net
Wed Aug 24 15:48:58 CEST 2005


Frames can only have a fixed-color background.

However, it is possible to give a label widget an image, and then use that
label more or less like a frame.  This doesn't include the ability to tile the
image. (You could replace the label with a canvas, and create multiple image
objects on the canvas, to achieve this effect---I'll leave this as an exercise)

Here's an example (replace "2313usb.gif" with something you have on your
system, it's just an image I had on hand).

The line 'l.pack_propagate(0)' tells Tk to make the 'l' widget take the
size of its image or label, not the size it would take based on its children.

	# label_as_frame.py
	from Tkinter import *

	t = Tk()

	p = PhotoImage(file="2313usb.gif")
	l = Label(t, image=p)

	e = Entry(l, width=20)
	e.pack(side=TOP, anchor=W, padx=4, pady=4)
	e.focus()

	b = Button(l, command=t.destroy, text="Close")
	b.pack(side=BOTTOM, expand=Y, anchor=S)

	l.pack_propagate(0)
	l.pack()

	t.mainloop()

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050824/889c267e/attachment.pgp


More information about the Tkinter-discuss mailing list