Tk Source Code

View Ticket
Login
Ticket UUID: 3126428
Title: ttk::button does not show image change
Type: Bug Version: obsolete: 8.5.9
Submitter: oehhar Created on: 2010-12-03 08:36:32
Subsystem: 88. Themed Tk Assigned To: jenglish
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2016-09-22 00:05:33
Resolution: Fixed Closed By: patthoyts
    Closed on: 2016-09-22 00:05:33
Description:
A ttk::button displays an image.
If the image changes in a) contents or b) size, this is not correctly displayed.
A contents change is updated if the widget is redrawn.
A size change is only updated if the image is configured again to the button.
Within a non-themed button widget, an image change is directly displayed.

Sample procedure on an interactive wish8.5.9 and Windows Vista 32 bit Aero Theme:
% image create photo i -height 30 -width 30
% i put red -to 0 0 29 29
% pack [button .b1 -image i] [ttk::button .b2 -image i] [ttk::button .b3 -image i] -side left
#-> 3 red buttons

% i put black -to 0 0 29 29
#-> Only button 1 changes color

% .b2 configure -image i
#-> Button 2 changes color

# minimize and maximize window -> all button black

% i configure -width 100 -height 100
#-> only button 1 changes size

% .b2 configure -image i
#-> Button 2 changes size

# minimize and maximize window -> no change
User Comments: patthoyts added on 2016-09-22 00:05:33:
Applied patch to 8.5 and up.

patthoyts added on 2016-09-15 20:09:38:

This recently popped up in a Tkinter question at stackoverflow. The following Tcl script illustrates the issue based on the SO question:

package require Tk

variable BITMAP {
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
}
}

proc change_color {img_tk img_ttk index} {
    set colors [list "red" "yellow" "lime" "white" "magenta" "grey60"]
    $img_tk configure -foreground [lindex $colors $index]
    $img_ttk configure -foreground [lindex $colors $index]
    after 50 [list change_color $img_tk $img_ttk [expr {($index + 1) % [llength $colors]}]]
}

proc main {} {
    variable BITMAP
    set img_tk [image create bitmap -data $BITMAP]
    set img_ttk [image create bitmap -data $BITMAP]
    set label_tk [tk::label .l_tk -image $img_tk]
    set label_ttk [ttk::label .l_ttk -image $img_ttk]
    ttk::button .b -text Exit -command {set ::forever 1}

    grid $label_tk $label_ttk -padx 10 -pady 10 -sticky nw
    grid .b - -sticky se
    grid rowconfigure . 0 -weight 1
    grid columnconfigure . 0 -weight 1

    after 50 [list change_color $img_tk $img_ttk 0]
    bind . <Control-F2> {console show}
    wm protocol . WM_DELETE_WINDOW {set ::forever 1}
    vwait ::forever
    return 0
}

if {!$tcl_interactive} {
    if {![info exists initialized]} {
	set initialized 1
	set r [catch [linsert $argv 0 main] err]
	if {$r} {
	    tk_messageBox -icon error -title "blinker error" \
		-message $err -detail $::errorInfo
	}
	exit $r
    }
}
In this demo, both images should cycle through the colors, but the ttk label does not. The attached patch resolves this by hooking up the image changed callback function. It may be we don't really need an extra TtkGetImageSpecEx function and all instances of the internal function TtkGetImageSpec could be changed to take the two extra parameters needed. It't not on the stubs interface so seems internal only.


Attachments: