Updated 2014-02-01 16:16:27 by EB

EB, 2014/02/01 - The look of ttk::combobox in read-only mode doesn't match the one of Windows 7: in fact, Windows 7 now use a button with an arrow:

The code below uses ttk and TclOO to define a new combobox widget compliant to Windows 7 style:
package require Tk
package require TclOO

# Image and ttk element for the combobox arrow
image create photo RoComboboxArrow -data \

ttk::style element create RoCombobox.arrow image RoComboboxArrow

# RoCombobox style 
ttk::style layout RoCombobox {
    Button.button -sticky nswe -children {
        Button.padding -sticky we -children {
            RoCombobox.arrow -side right -sticky ""
            Combobox.textarea -sticky ew

ttk::style configure RoCombobox -padding 2

# RoCombobox bindings will be set before TCombobox
bind RoCombobox <Destroy> {%W destroy}
bind RoCombobox <Motion> { break }
bind RoCombobox <Enter> { %W instate !disabled {%W state active} }
bind RoCombobox <Leave> { %W state !active }

oo::class create RoCombobox {
    self unexport new create destroy

    self method unknown {w args} {
        set w [ttk::combobox $w {*}$args -style RoCombobox -state readonly]
        my create obj
        rename $w [info object namespace obj]::widget
        rename obj ::$w
        bindtags $w [linsert [bindtags $w] 1 RoCombobox]
        return $w

    method selection {args} {
        # Overridden to avoid text selection

    forward unknown widget

# Prevent ttk code to set focus on the RoCombobox widget
proc ttk::combobox::focus {w} {
    if {![info object isa object $w] ||
        ![info object isa typeof $w RoCombobox]} {
        ::focus $w

The following code shows the RoCombobox and ttk::combobox together:
set values {"First value" "Second value" "Third value"}
pack [RoCombobox .cb1 -values $values] -padx 10 -pady 10
.cb1 current 0
pack [ttk::combobox .cb2 -state readonly -values $values]  -padx 10 -pady 10
.cb2 current 0

Now I'd like to have the listbox with the drop shadow as shown at the top of the page. I guess it's possible using twapi, but have not found how yet.