Home > Archive > Tcl > June 2006 > Embedding an image in an entry widget
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Embedding an image in an entry widget
|
|
| Kevin Walzer 2006-06-24, 8:23 am |
| I'm trying to jazz up an entry widget in one of my applications with an
image of a magnifying glass embedded directly in the entry widget
itself. Right now I pack a label with the image on it directly adjoining
the entry widget, but a lot of applications (including Thunderbird,
which I'm using to type this) make a compound widget with the image
"inside" the entry field.
I've not found any examples that illustrate how to do this. Can this be
done in straight Tcl/Tk or is some OO megawidget (snidget) called for?
Any examples are appreciated.
--
Kevin Walzer
Poetic Code
http://www.kevin-walzer.com
| |
| Bruce Hartweg 2006-06-24, 8:23 am |
| Kevin Walzer wrote:
> I'm trying to jazz up an entry widget in one of my applications with an
> image of a magnifying glass embedded directly in the entry widget
> itself. Right now I pack a label with the image on it directly adjoining
> the entry widget, but a lot of applications (including Thunderbird,
> which I'm using to type this) make a compound widget with the image
> "inside" the entry field.
>
> I've not found any examples that illustrate how to do this. Can this be
> done in straight Tcl/Tk or is some OO megawidget (snidget) called for?
> Any examples are appreciated.
>
you can actually pack/place the label inside the entry widget itself
and get the look you're after, except that it'll cover the first <n>
characters of text (where n depends on the image size), alternatively
you can create a frame with the color/relief options set to appear like
and entry, then pack the label & entry inside of it (with -releief flat
-bd 0). You can do this fairly simply in pure Tk but you could also
wrap it into a megawidget framework so it appears and behaves as an
entry widget, but gives an extra option to add (and probably anchor)
an image.
Bruce
| |
| Roy Terry 2006-06-24, 8:23 am |
|
"Bruce Hartweg" <bruce-news@hartweg.us> wrote in message
news:3Jimg.6$kF2.2@dfw-service2.ext.ray.com...
> Kevin Walzer wrote:
>
> you can actually pack/place the label inside the entry widget itself
> and get the look you're after, except that it'll cover the first <n>
> characters of text (where n depends on the image size), alternatively
> you can create a frame with the color/relief options set to appear like
> and entry, then pack the label & entry inside of it (with -releief flat
> -bd 0). You can do this fairly simply in pure Tk
And here is one demo
package require Tk
package require Img
destroy .joe
toplevel .joe
set ifile <small image file name here>
set i [image create photo -file $ifile]
pack [entry .joe.eplain] -side top -anchor w -padx 5 -fill x
pack [frame .joe.f -relief sunken -bd 2 -bg systemwindow -height 18] -side
top -anchor w -padx 5 -fill x -pady 5
pack [label .joe.f.i -image $i -bd 0 -bg systemwindow] -side left -padx
1 -pady 1
pack [entry .joe.f.e -bd 0] -side left -fill both -expand yes
Roy
> Bruce
| |
| Bryan Oakley 2006-06-24, 8:23 am |
| Kevin Walzer wrote:
> I'm trying to jazz up an entry widget in one of my applications with an
> image of a magnifying glass embedded directly in the entry widget
> itself. Right now I pack a label with the image on it directly adjoining
> the entry widget, but a lot of applications (including Thunderbird,
> which I'm using to type this) make a compound widget with the image
> "inside" the entry field.
>
> I've not found any examples that illustrate how to do this. Can this be
> done in straight Tcl/Tk or is some OO megawidget (snidget) called for?
> Any examples are appreciated.
>
Just hide the entry widget inside a frame. Remove the border from the
entry and add a border to the frame. Make sure the frame has the same
background as the entry.
Here's an example; you might have to tweak padding, highlightthickness
or whatnot, but it illustrates the general principle.
frame .uberentry -bd 1 -relief sunken
menubutton .uberentry.mb ...
entry .uberentry.entry -borderwidth 0
pack .uberentry.mb -side left
pack .uberentry.entry -side left -fill both -expand 1
.uberentry configure -background [.uberentry.entry cget -background]
If you use tile, it's probably possible to add another element inside a
custom layout. In fact, I think Jeff Hobbes may have done that in just
the last day or so. Hunt down the tile mailing list archives.
--
Bryan Oakley
http://www.tclscripting.com
|
|
|
|
|