Я пишу шкалу tcl, но мне нужно контролировать разрешение шкалы. Шкала идет от 10 до 100 и имеет разрешение 1 в коде ниже:
#!/bin/sh
####################################################################### \
exec /sw/freetools/tk/8.5.6/Linux/rh5/x86_64/bin/wish8.5 "$0" ${1+"$@"}
package require Tk
font create FONT1 -family {DejaVu Sans Mono} -size 7 -weight normal
font create FONT2 -family {DejaVu Sans} -size -8 -weight normal -slant roman
ttk::style configure rule1.TCombobox -background lavender \
-foreground black \
-fieldbackground mistyrose2 \
-padding 0.5
ttk::style map rule1.TCombobox -fieldbackground [list readonly gray98]
frame .frame_F1 -background gray98 -highlightbackground black -highlightthickness 1
frame .frame_F1.top -background gray98 -highlightbackground red -highlightthickness 0
frame .frame_F1.bottom -background gray98 -highlightbackground blue -highlightthickness 0
pack .frame_F1 -padx 10 -pady 10
pack .frame_F1.top -side top -anchor w
pack .frame_F1.bottom -side bottom -anchor w
label .frame_F1.bottom.scale_text1 -text " scale" -foreground black -background gray98 -font FONT1 -justify left
label .frame_F1.bottom.scale_text2 -text "resolution" -foreground black -background gray98 -font FONT1 -justify left
entry .frame_F1.bottom.scale_value -textvariable ::SCALE -foreground black -width 5 -justify right -state readonly
ttk::combobox .frame_F1.bottom.cbox -style rule1.TCombobox \
-values [list 1 2 3 4 5] \
-font {-size 8} \
-width 4 \
-justify center
.frame_F1.bottom.cbox set "--"
.frame_F1.bottom.cbox set "1"
.frame_F1.bottom.cbox configure -state readonly
set RESOLUTION 1
bind .frame_F1.bottom.cbox <<ComboboxSelected>> {
switch [%W get] {
"1" {set RESOLUTION "1"}
"2" {set RESOLUTION "2"}
"3" {set RESOLUTION "3"}
"4" {set RESOLUTION "4"}
"5" {set RESOLUTION "5"}
}
}
scale .frame_F1.top.scale -orient horizontal \
-variable ::SCALE \
-length 210 \
-from 10 -to 100 \
-tickinterval 10 \
-resolution $RESOLUTION \
-showvalue false \
-background gray98 \
-font FONT2 \
-foreground black \
-width 12 \
-highlightthickness 0 \
-borderwidth 2 \
-sliderrelief groove \
-sliderlength 18
pack .frame_F1.top.scale
grid .frame_F1.bottom.scale_text1 -row 1 -column 0
grid .frame_F1.bottom.scale_value -row 1 -column 1
grid .frame_F1.bottom.scale_text2 -row 2 -column 0
grid .frame_F1.bottom.cbox -row 2 -column 1
Результат:
![enter image description here](https://i.stack.imgur.com/z68Vy.jpg)
Затем я попытался два других примера добавления переменной для разрешения:
set RESOLUTION [.frame_F1.bottom.cbox get]
scale .frame_F1.top.scale -orient horizontal \
-variable ::SCALE \
-length 210 \
-from 10 -to 100 \
-tickinterval 10 \
-resolution $RESOLUTION \
=> но это не работает. Я также пытался извлечь переменную из привязки, но тоже потерпел неудачу ..
bind .frame_F1.bottom.cbox <<ComboboxSelected>> {
switch [%W get] {
"1" {set RESOLUTION "1"}
"2" {set RESOLUTION "2"}
"3" {set RESOLUTION "3"}
"4" {set RESOLUTION "4"}
"5" {set RESOLUTION "5"}
}
}
Есть идеи?