Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 .menu.help -tearoff 0 .menu.help add command -label {brief explanation... (F1)} -command exp +lainBox .menu.help 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 .menu.help -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


In reply to Re: clunky Tk GUI by vkon
in thread clunky Tk GUI by honyok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found