[Tkinter-discuss] Making an image the background of a Frame

Michael O'Donnell michael.odonnell at uam.es
Sun Jul 20 03:32:21 CEST 2008


Hi,

I ran the following on my Mac running python2.5.2 under Panther:
from Tkinter import*

root = Tk()
cwgt=Canvas(root)
cwgt.pack(expand=True, fill=BOTH)
image1=PhotoImage(file="pict.gif")
# keep a link to the image to stop the image being garbage collected
cwgt.img=image1
cwgt.create_image(0, 0, anchor=NW, image=image1)
b1=Button(cwgt, text="Hello", bd=0)
cwgt.create_window(20,20, window=b1, anchor=NW)
root.mainloop()

(supply your own 'pict.gif')

The canvas shows the image as background, and
the button on top, functional. However, the button's
normal border is there in white (see img below).Would be good to have a
button
with a transaprent background, but buttons in Mac Tkinter
are the MacOS buttons, which are hard to change.


Mick




On Sun, Jul 20, 2008 at 2:12 AM, Guilherme Polo <ggpolo at gmail.com> wrote:
> On Sat, Jul 19, 2008 at 8:30 PM, Tim Jones <timj at tolisgroup.com> wrote:
>> On Jul 19, 2008, at 4:20 PM, Alexnb wrote:
>>
>>> Guilherme Polo wrote:
>>>>
>>>> On Sat, Jul 19, 2008 at 7:43 PM, Alexnb <alexnbryan at gmail.com> wrote:
>>>>>
>>>>> So, is there a way I can make the background of a frame an image and
>>>>> still have all the widgets (buttons in this case) remain where they
are and
>>>>> how
>>>>> they work?
>>>>
>>>> You could just use a Label with a image and use this Label as the
parent
>>>> for other widgets you want to place over it. You will probably also
want to
>>>> set the window geometry according to this background image dimensions.
>>>>
>>> Okay, I tried that and the area just showed up white :(. What do you
>>> suggest?
>>
>> Unfortunately, this is one of the aspects of TK that isn't quite right on
OS
>> X.  You could use a drawn image of a button on your backdrop image and
then
>> monitor for the mouseclick position to determine that the pseudo-button
was
>> pressed, but without proper ties to the Carbon Compositor, it's best to
use
>> pushbuttons only on default, blank backgrounds.
>>
>
> Does that happen when using a Canvas too ? Same in Tk 8.5 ? I'm
> curious, mainly because I don't have a mac to test.
>
>> Sorry the news isn't better.
>>
>> Tim
>>
>> _______________________________________________
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
>> http://mail.python.org/mailman/listinfo/tkinter-discuss
>>
>
>
>
> --
> -- Guilherme H. Polo Goncalves
> _______________________________________________
> 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/20080720/0ea39984/attachment-0001.htm>


More information about the Tkinter-discuss mailing list