如何控制刻度tk / tcl小部件的分辨率?

问题描述 投票:0回答:1

我正在编写刻度尺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

然后,我尝试了另外两个示例,为该分辨率添加变量:

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"}
 }
}

到目前为止有什么主意吗?

我正在编写刻度尺tcl,但我需要控制刻度尺的分辨率。刻度从10变为100,以下代码中的分辨率为1:#!/ bin / sh ########################### ########### ...

tcl scale resolution
1个回答
0
投票

尝试将组合框绑定更改为:

© www.soinside.com 2019 - 2024. All rights reserved.