Width Tcl / Tk LstBox in CombBox

How to adjust the width of the list component in the drop-down list so that it matches the longest record? The width of the widget itself (the recording component) may be short, but I'm looking for a way to customize the list component that will be wider than the recording ...

+2
source share
1 answer

It is possible, but not without hacking;)

You can find the combobox implementation in combobox.tcl(in my case /usr/share/tcltk/tk8.5/ttk/combobox.tcl. There you see that if you have combobox

set cb [ttk::combobox .cb -state readonly]

and call it, it creates the following structure of the internal widgets:

$cb.popdown.f.l

popdown - , , combobox, f l , . , popdown .

, script ButtonPress combobox, , ( puts [bindtags $cb]):

.cb TCombobox . all

, (.cb), (TCombobox), (.) , , , , , script, popdown toplevel, .

, :

bindtags $cb [list TCombobox $cb . all]

! :

package require Tk                                                              

wm title . "Combobox Listbox resize"                                            
wm geometry . "150x40"                                                          
grid columnconfigure . 0 -weight 1                                              
set cb [ttk::combobox .cb -width 20 -state readonly]                            
grid $cb -row 1 -column 0 
set cmd "$cb configure -values {abarsdhresntdaenstdsnthret erstihre reshterhstierht}"
$cb configure -postcommand $cmd                                                 
bind $cb <ButtonPress> changeGeomPopdown
bindtags $cb [list TCombobox $cb . all]                                         

proc changeGeomPopdown { } {                                                    
    global cb                                                               
    scan [wm geometry $cb.popdown] "%dx%d+%d+%d" w h x y
    wm geometry $cb.popdown "300x${h}+${x}+${y}"                            
}

, [1]:

$cb.popdown.f.l cget -font

font measure ([2]) , , , . , .

. , , ​​ , , ttk::combobox ,


[1] http://www.tcl.tk/man/tcl8.5/TkCmd/listbox.htm#M16
[2] http://www.tcl.tk/man/tcl8.5/TkCmd/font.htm#M10

0

Source: https://habr.com/ru/post/1657051/


All Articles