Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (11)
    As of 2021-01-25 12:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?