I am using PerlTK to build a GUI for a programmable keyboard. The script has a TK has a widget for each key on the keyboard. Each key has over 100 legal values. I have found this list to be too long for optionmenu type widget. So I borrowed the 'native_optionmenu' widget from the mastering Perl/TK book Chapter 12. The widget is similiar to optionmenu but allows for multiple columns.

A reduced version of my script that instantiates just one widget:

use Tk 800.000; use strict; my $width=45; # just right for 4 capital letters my $height=30; my @key_array = (); @key_array = split (//, "abcdefghijklmnopqrstuvwxyz"); @key_array = (@key_array, split (//, "0123456789" ) ); @key_array = (@key_array, qw(F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12) ) +; @key_array = (@key_array, qw(F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F +23 F24) ); @key_array = (@key_array, qw(Esc Bksp Del Ins Home End PgUp PgDn CapLk + Enter) ); @key_array = (@key_array, qw(Shift Ctrl Alt UpArr DnArr LtArr RtArr Pa +use) ); my $vvalue=""; my $mw = MainWindow->new; my $code_font = $mw->fontCreate('code', -family => 'ariel', -size => 1 +0); native_optionmenu( $mw, \$vvalue)->place( -width => $width, -height = +> $height); MainLoop; sub native_optionmenu { my($parent, $varref, ) = @_; my @optionvals = @key_array; my $mb = $parent->Menubutton( -textvariable => $varref, -indicatoron => 0, -relief => 'raised', -borderwidth => 2, -highlightthickness => 2, -anchor => 'c', -direction => 'flush', -font => $code_font, ); my $menu = $mb->Menu(-tearoff => 0); $mb->configure(-menu => $menu); my $ii =0; foreach (@optionvals) { $menu->radiobutton( -label => $_, -variable => $varref, ); $menu->entryconfigure($ii, -columnbreak => 1) unless $ii++ % 2 +6; } $mb; } # end native_optionmenu
My PerlTK script has several Notebook tabs. Each tab has around 50 native_optionmenu button and each button has greater than 40 widgets.

My issue is when I get up to around 170 instances of native_optionmenu (across multiple tabs), then active perl on windows XP goes crazy. My widgets disappear. Clicking on the notebook tabs causes widgets to appear OUTSIDE the TK GUI window.

I am looking for suggestions on how to improve the performance. I think the issue is just too many widgets. I think if the native_optionmenu sub called another sub that poped up the window, then the performance would be better. I am not good enough yet with PerlTK to make the tweak. I am looking for tips.

In my perl script where I call the native_optionmenu, If replaces the call to 'Button' and the problem goes away.

Works: $$win->Button( -textvariable => \$vvalue$layout$layer$finger$direction)->place(-x => $colpos, -y => $rowpos, -width => $width, -height => $height);

Buggy behavior: native_optionmenu( $$win, \$vvalue$layout$layer$finger$direction)->place(-x => $colpos, -y => $rowpos, -width => $width, -height => $height);

Suggestions?


In reply to Multi column option menu by gator456

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, details, 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, summary, 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.