Re: Buttons with icons but without boxes on macOS and Tcl::pTk
[email protected] (Christopher Chavez) Wed, 27 Feb 2019 06:15:55 -0600
| Newsgroups | perl.tcltk |
|---|---|
| Message-ID | <[email protected]> |
> On Feb 27, 2019, at 2:58 AM, welle Ozean via tcltk <[email protected]> = wrote: >=20 > Hello, >=20 > using Tcl::pTk I want to move from the ttkButton to a plain clickable = (png) icon on gray background. I do not want the icon in a box, which is = the standard rendering of buttons, as far as I understand. This looks = very odd nowadays. At best, the icon should be accompanied by a test, as = this screenshot shows: https://ibb.co/dfYwKvM >=20 > On a mailing list I get the following Tcl/Tk answers: >=20 > 1) If you add -style Toolbutton to the ttk::button, the button will = look flat and modern. Adding "-compound top" will allow to specify both = image and text. >=20 > 2) set i1 [image create photo -file icon.png] > button .b -image $i1 -text Open -compound top -relief flat > pack .b > Note that colors for the button widget and/or colors/transparency = in=20 > the png image will need to be adjusted so the icon and the button = area=20 > fit together seamlessly.=20 >=20 > No matter how many combinations I tried, I could not achieve my result = (I always had boxes around the icons, so that I think that Tcl::pTk does = not support much tweaking of the buttons. Has I guess this is the = simplest way to display icons on modern interfaces, maybe somebody here = has already achieved this result. >=20 > Welle Hi Welle, Are you trying this on Tk Aqua? If the ttk theme is set to the 'aqua' = theme (the default), then it seems neither of those approaches yield = box-less buttons. I suspect the repliers to your post on comp.lang.tcl = were unaware of the behavior on aqua, since both approaches seem to work = on Windows and X11=E2=80=94though on Windows the first approach (ttk = Toolbutton) looks better because the buttons will actually highlight = when hovered, while on X11 the second approach (flat regular button) = looks better because it highlights without showing a raised border when = hovered. A workaround might be to use the first approach (the second approach = seems unaffected) along with $mw->ttkSetTheme() to select a non-'aqua' = ttk theme (such as the 'default' theme) for which the buttons render = more properly, however this will affect *all* ttk widgets. Ideally a bug = should be filed with Tcl/Tk requesting that Toolbuttons and flat-relief = buttons be implemented/rendered properly on the 'aqua' theme. The syntax for both approaches seems already supported in Tcl::pTk. For = the first approach, use $mw->ttkButton(-style =3D> 'Toolbutton', =E2=80=A6= ). For the second approach, use $mw->Button(-relief =3D> 'flat', =E2=80=A6= ). Hope this helps Christopher Chavez=