------------------------------------------------------------------------------- Command Line Arguemnts and Resources See manpage for module Tk::CmdLine Command line arguments are automatcially extracted from the ARGV array when you either call Tk::CmdLine::SetArguments() OR you create the main window $wm=MainWindow->new(); As such you should create you main window (or SetArguments) BEFORE you parse the ARGV array for your program specific arguments. ------------------------------------------------------------------------------- Extra Data associated with a widget Perl/Tk widgets are represented as references to hashes. You can store whatever you like in the hash. Names starting and ending with _ e.g. $widget->{_MINE_} are reserved for core (though I am lax about that). There is also a hook : my $hash = $widget->privateData(); # key is caller's package name my $hash = $widget->privateData('MyKey'); # explcit key Which will return a sub-hash which is "your very own". Nick Ing-Simmons ------------------------------------------------------------------------------- Multiple Listboxes - only one item in any of them selected By default Listbox has -exportselection => 1 so Listbox's selection is also the X 'PRIMARY' selection - X mandates that only one window can own an X selection at a time. So when one Listbox asserts it the other one looses it. The fix is to turn off -exportselection on one or both of the listboxes. Presumably the exportselection works slightly differently if multiple selection listboxes are being used. ------------------------------------------------------------------------------- Text/Entry widget callback on Enter Use a bind with.. $input_widget->bind("" => sub { ... }); ------------------------------------------------------------------------------- Scrolled Canvas: Problem with raise() and lower(). When using the scrolled method to create a canvas, it seems as if the $canvas->raise(); and $canvas->lower(); commands are trying to raise the $canvas as a "window" rather than raise or lower the actual canvas object's within the window. The problem is that Scrolled returns the pointer for the frame containing the canvas widget, and not the widget itself. And unknown or extra methods are however ``Delegates()'' to the contained sub-widget. When you create a Canvas with Scrolled, you have to ask for the Canvas using Subwidget(). to use raise and lower on the objects and not the frame window. Example Solution... my $frame=$top->Scrolled('Canvas', -scrollbars=>'se', -scrollregion=>\@scrollregion); my $canvas=$frame->Subwidget('canvas'); ------------------------------------------------------------------------------- Resizing a Font on the fly use Tk; use Tk::Font; $top = new MainWindow; $f = $top->fontCreate(-size => 20, -family => "helvetica"); $c=$top->Canvas->pack; $c->createText(100,50,-text => "bla blubber", -font => $f); $c->createText(30,150,-text => "foo bar", -font => $f); $top->Button(-text => "Smaller", -command => sub { $f->configure(-size => $f->actual(-size)-1); })->pack; MainLoop; ------------------------------------------------------------------------------- Adding a Method to an Existing Widget The "clean way" - create a subclass: package Tk::MyWhatever; use base qw(Tk::Whatever); Construct Tk::Widget 'MyWhatever'; # you could clobber 'Whatever' too sub new_method { ... } 1; __END__ The easy way : use Tk::Whatever (); # make sure module is loaded. sub Tk::Whatever::new_method { ... } The above is a little tricky in a way that may not be an issue to you: the _body_ of the sub is executed in the enclosing "package" rather than Tk::Whatever. If that does matter then do it this way instead: use Tk::Whatever (); { package Tk::Whatever; sub new_method { ... } } Note that in none of these cases can "new_method" see any "my" variables in Tk/Whatever.pm - it will see the "my" variables in file it is in (which is what lexical scoping is all about) which can be handy. As far as I know all Tk core classes which have global 'my' variables (e.g. MainWindow's list of windows) have access methods to get at them. Nick Ing-Simmons ------------------------------------------------------------------------------- Speeding up Complex Canus Draws A possible solution: packForget the canvas while drawing the lines onto the canvas, and the re-pack() the canvas again. For speeding up drawing lines: try to draw as many as possible line segments with one createLine()-call. It's significantly faster. If you like, you can also use the Tk API functions to draw lines in an XS module. This will be about 2-3x faster. ------------------------------------------------------------------------------- Drawing Dotted lines on a Canvas Does anyone know how to make dotted lines on a canvas? (not a bunch of little lines) The following works fine for X Windows but failed for Win95 use Tk; $mw = new MainWindow(-name => 'test', -title => 'test'); $can = $mw->Canvas; $can->pack(-fill => both, -expand => yes); $gridsize = 20; # Create the dots bitmap my (@bits); for (my $i = 0; $i < $gridsize; $i++) { if ($i == 0) { $bits[$i] = "1"; } else { $bits[$i] = "."; } } print @bits; push @bitmaps, pack('b8' x $gridsize, @bits); $mw->DefineBitmap('dots' => 8, $gridsize, $bitmaps[-1]); $can->create('line', 30, 0, 30, 300, -stipple => 'dots', -width => 8); MainLoop; ------------------------------------------------------------------------------- Build Hint Nick Ing-Simmons writes: >Tim Evans writes: >>I've been trying to install Tk400.202 on a Solaris 7 (i.e., 2.7), >>with perl 5.005_57. I get numerous undefined's referencing 'sv_undef' >>and also 'sv_arenaroot'. > >If you are brave enough to use 5.005_57 the you should consider Tk800.014. > >But that said - read the 5.005_57 docs - you need to set the "POLLUTE" >option so that 5.005_57 fills the name space with lots of #defines >the way 5.000 .. 5.004 did. > >IRRC > >perl Makefile.PL POLLUTE=1 That is not quite sufficent - Tk400.* is a little too intimate with perls "magic" vtables (which even POLLUTE does not #define back to old style): So you also need this 3-char tweak: --- /tmp/Tk400.202/tkGlue.c% Fri Jul 16 09:47:26 1999 +++ /tmp/Tk400.202/tkGlue.c Fri Jul 16 09:47:26 1999 @@ -2694,7 +2694,7 @@ mg->mg_obj = 0; mg->mg_type = 'U'; mg->mg_len = 0; - mg->mg_virtual = &vtbl_uvar; + mg->mg_virtual = &PL_vtbl_uvar; mg_magical(sv); New(666, ufp, 1, struct ufuncs); Then it builds for me with gcc-2.8.1, perl5.005_57, solaris7. -------------------------------------------------------------------------------