Tk Source Code

View Ticket
Login
Ticket UUID: e7ac02121f4c9aaf822fa5b76f0e5d6834a9f53c
Title: bad reqheight after update idletask and strange border
Type: Bug Version: 8.6
Submitter: anonymous Created on: 2017-01-15 00:28:49
Subsystem: 88. Themed Tk Assigned To: jenglish
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2017-01-23 07:29:25
Resolution: None Closed By: nobody
    Closed on:
Description:

I tested on Linux Mint and on Windows 8.

The code below shows a border but the label is over the border. Also It seems that the default borderwidth is 1. Maybe the calculation of winfo reqheight is not right.

::ttk::frame .d -relief groove
label .d.l -text "This is a label"
pack .d.l

update idletasks
place .d -width 100 -height [winfo reqheight .d]

If I add a borderwidth option the situation is solved, at least on linux. On windows 8 I have to add a borderwidth of 2 to avoid the label over the frame

::ttk::frame .d -relief groove -borderwidth 1
label .d.l -text "This is a label"
pack .d.l

update idletasks
place .d -width 100 -height [winfo reqheight .d]

User Comments: fvogel added on 2017-01-23 07:16:17:

I had started crafting something along the following lines, but did not find what value to give to the shiftRelief parameter of Ttk_RelievePadding(). Here the start of a patch, with shiftrelief forced to zero (thus no effect of the patch):

Index: generic/ttk/ttkFrame.c
==================================================================
--- generic/ttk/ttkFrame.c
+++ generic/ttk/ttkFrame.c
@@ -79,10 +79,21 @@
        int border = 0;
        Tk_GetPixelsFromObj(NULL,
            framePtr->core.tkwin, framePtr->frame.borderWidthObj, &border);
        margins = Ttk_AddPadding(margins, Ttk_UniformPadding((short)border));
     }
+
+    /* Add padding for relief:
+     */
+    if (framePtr->frame.reliefObj) {
+        int relief = TK_RELIEF_FLAT;
+        Ttk_Padding paddingPtr;
+
+        Tk_GetReliefFromObj(NULL, framePtr->frame.reliefObj, &relief);
+        paddingPtr = Ttk_RelievePadding(margins, relief, 0);
+       margins = Ttk_AddPadding(margins, paddingPtr);
+    }

     return margins;
 }

 /* FrameSize procedure --

Anyway, this is perhaps the completely wrong direction to go. Left to JE, thanks!


fvogel added on 2017-01-23 07:08:26:

Thanks for the link to the wiki. Quoting Joe English from that link: "The ttk::frame widget only looks at the -borderwidth and -padding widget options when determining its internal padding, it doesn't take this from the layout."

OK, so this is a bug in ttk. I think Joe referred to these lines.

Can I assign to you then, Joe? Feel free to remove assignment if you're not comfortable with taking on this issue. Thanks!


bll (claiming to be [email protected]) added on 2017-01-22 17:02:40:
Testing on linux with 8.6.1:

It appears to me that the requested height for a ttk::frame is used for the final height and the border is drawn within that requested height.

Whereas for a standard frame, the border is drawn outside of that requested height, and the final height is larger than the requested height.

This inconsistency is a problem, because if it were fixed, it could break many user's layouts (who already have a +2 or equivalent).

Reported in 2007, but never fixed: http://wiki.tcl.tk/%0920152

anonymous added on 2017-01-22 16:07:39:
But the same problem happens on Linux (not also on Windows). And Linux has no native theme.

fvogel added on 2017-01-21 16:23:29:

Note that the default theme I used (on my Win platform) is vista.

When using:

    ttk::style theme use classic

then ttk::frame and tk::frame show the same display, because with the classic theme, this function is used for drawing and it actually checks for the size of the border before drawing it.

Issue, if there is one, seems to be in the native themes. Not sure something can be done there.


fvogel added on 2017-01-21 15:34:48:

I believe that what you see is due to the relief being drawn for ttk::frame even if the borderwidth is zero, which is not the case with a tk::frame.

Test script:

package require Tk

wm geometry . 600x300

label .l1 -text "ttk::frame with zero borderwidth, -relief groove is drawn nevertheless:"
place .l1 -x 0 -y 0

::ttk::frame .d -relief groove
label .d.l -text "This is a label" -background red
pack .d.l

update idletasks
place .d -x 10 -y 20 -width 100 -height [winfo reqheight .d]


label .l21 -text "tk::frame with zero borderwidth, no relief is drawn despite -relief groove is specified:"
place .l21 -x 0 -y 50

frame .dd1 -relief groove
label .dd1.l -text "This is a label" -background orange
pack .dd1.l

update idletasks
place .dd1 -x 10 -y 70 -width 100 -height [winfo reqheight .dd1]


label .l22 -text "the same tk::frame with zero borderwidth and -relief groove, with blue background set only to visualize the frame:"
place .l22 -x 0 -y 100

frame .dd2 -relief groove -background lightblue
label .dd2.l -text "This is a label" -background orange
pack .dd2.l

update idletasks
place .dd2 -x 10 -y 120 -width 100 -height [winfo reqheight .dd2]


label .l3 -text "ttk::frame with non-zero borderwidth, -relief groove is still drawn:"
place .l3 -x 0 -y 150

::ttk::frame .ddd -relief groove -borderwidth 5
label .ddd.l -text "This is a label" -background red
pack .ddd.l

update idletasks
place .ddd -x 10 -y 170 -width 100 -height [winfo reqheight .ddd]


label .l4 -text "tk::frame with non-zero borderwidth, -relief groove is now drawn:"
place .l4 -x 0 -y 200

frame .dddd -relief groove -background lightblue -borderwidth 5
label .dddd.l -text "This is a label" -background orange
pack .dddd.l

update idletasks
place .dddd -x 10 -y 220 -width 100 -height [winfo reqheight .dddd]


anonymous added on 2017-01-15 15:11:58:

This situation only happens with ::ttk::frame. There is no strange behaviour using frame command on Windows 8 and on Linux Mint.