0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

3回まわってワン!

0
Posted at

例えば以下のようなスクリプトを作ります。

hello.tcl
# !/bin/sh
# -*-mode:tcl:coding:cp932;tab-width:8-*-\
	exec wish "$0" ${1+"$@"}
grid columnconfigure . 0 -weight 1
grid [label .w1 -text "Hello, world!"] -sticky we -padx 10 -pady 5
grid [button .w2 -text "Quit" -command exit] -sticky we -padx 10 -pady 5
bind .w1 <Triple-Button-1> [list console show]

実行すると↓こんな感じ。
hello.png

おもむろに「Hello, world!」を3回クリックします。すると↓こんなウィンドウ(Console)が開きます。
console.png

そしてConsoleで

.w2 configure -relief groove

と入力してEnterキーを叩くと、↓こんな感じにボタンの縁が変わります。
groove.png

Consoleの右上の☓をクリックしてConsoleを閉じても、もちろんhelloウィンドウはそのままです。

こんな感じで隠しモードとしてConsoleを出せるようにしておくと、デバッグやGUIの調整のみならず、関数を直接呼び出して隠しコマンド的に使うなど、地味に便利です。

デバッグ用の使い方としては、スクリプトに

puts "DEBUG: a=$a"

と書いておけば、Consoleにputsによる出力が表示されます。

まぁ別に3回まわってトリプルクリックじゃなくてもいいんですが、簡単に実装できて、それでいて誤操作でトリプルクリックになっちゃうことがほぼ無い、というのは一石二鳥です。

ちなみに標準のコンソールの代わりにTkConを使った方が便利なんですが、それはまた機会があれば紹介したいとおもいます。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?