Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: clunky Tk GUI

by vkon (Curate)
on Jan 21, 2009 at 12:23 UTC ( #737807=note: print w/replies, xml ) Need Help??

in reply to clunky Tk GUI

because of this hairy Tk GUI code, I switched to a different Tk programming technique in all my programs.

The idea is to use pure-Tcl/Tk for constructing GUI, but then use perl/Tk style for operating widgets.

use strict; use Tcl::Tk; my $mw = Tcl::Tk::tkinit; my $int = $mw->interp; $int->Eval(<<'EOS'); # here goes pure-Tk GUI creation package require BWidget package require tooltip menu .menu -tearoff 0 menu .menu.file -tearoff 0 menu -tearoff 0 add command -label {brief explanation... (F1)} -command exp +lainBox add command -label {About...} -command aboutBox .menu.file add separator .menu.file add command -label Exit -command {destroy .} .menu add cascade -menu .menu.file -label File .menu add cascade -menu -label Help . config -menu .menu wm title . {Here goes the title} pack [text .t -wrap none -font "Courier 8"] -expand 1 -fill both pack [button .b -text "test button" -command "puts this"] -fill x tooltip::tooltip .b "helper tooltip" # and now 2 helper dialog boxes: proc aboutBox {} { Dialog .about -modal local -separator 1 -title {about...} pack [message [.about getframe].m1 -text {author - me}] .about add -name Ok -text Ok .about setfocus 0 .about draw destroy .about } proc explainBox {} { Dialog .explain -modal local -separator 1 -title {brief explanatio +n} set vt [.explain getframe] pack [message $vt.m1 -text {This program does foo bar fluffy, bla- +bla-bla} -width 450] .explain add -name Ok -text Ok .explain setfocus 0 .explain draw destroy .explain unset vt } bind . <Key-F1> explainBox bind . <Control-Key-F1> aboutBox EOS # bind Tcl/Tk widget to the perl/Tk my $t = $int->widget(".t",'Text'); # do anything with perl/Tk syntax $t->insert('end','some-text'); $t->see('end'); $int->MainLoop;

Same GUI creation perl/Tk will be thrice as much code.

This technique requires some additional efforts to start with, but I get very much benefits, so I never look back

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://737807]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-01-26 12:47 GMT
Find Nodes?
    Voting Booth?