English 中文(简体)
Tcl/Tk 制成子,在被点击时改变颜色?
原标题:Tcl/Tk script to make a button that switches colour when clicked?

仅仅使Tcl/Tk方案真正简单易懂,但我没有什么麻烦。

在被点击时,我需要打上ton子的颜色,这样,它就会开始红色,被点击就会变成绿色,如果再点击就会回红。

I have got it changing from red to green, but I don t know how to make it go back the other way. What is the best way to do this?

最佳回答

这并非非常困难(除了在OSX上,这种事情是directly<>/em>,反对平台协调准则)。

button .b -background red -command [list toggleTheButton .b]
set state(.b) 1
proc toggleTheButton w {
    global state
    if {$state($w)} {
        $w configure -background green
    } else {
        $w configure -background red
    }
    set state($w) [expr {!$state($w)}]
}

考虑使用<代码>checkbutton 相反,当你们需要聚合时,因为用户会更迅速地理解它。

问题回答

暂无回答




相关问题
How to create data structure in Tcl?

I am translating some lisp code to Tcl and wonder if there is anything like lisp s defstruct in Tcl for creating data structures? If nothing is built into Tcl, what extension packages to Tcl would ...

(Tcl/Expect) clear screen after exit

I want to clear the screen (on the local machine) after exiting from my (semi) interactive expect script. Can I do that from within the script? Here s what I tried, that failed. #!/usr/bin/expect -f ...

Implementation question in web-development

We are testing a DSL modem s web pages (the HTTP server is running on the modem). We have an automation tool that configures various options on the web pages by sending POSTS of the respective web ...

Linking Tcl/Tk to Python 2.5

I have an existing Python 2.4 and it is working properly with tkinter as I tested it using python import _tkinter import Tkinter Tkinter._test() Now, I have installed ...