Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Creating dynamic Tk buttons??

by Anonymous Monk
on Jun 06, 2003 at 13:37 UTC ( [id://263654]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the following sub-routine to create butons on the fly for my Tk app, but my problem is that for every call to the routine the new buttons are getting appended to the old. (i.e. my list of buttons grows.) Does anyone know of a simple solution to the problem?
sub button_setup($prog_select) { my $prog = shift; foreach my $key (keys %{$button{$prog}}) { my $key = $buttons->Button( -text => $key, -width => '10', -command => sub {system "$button{$prog}{$key}";} )->pack(-side => 'top', -pady=>'10'); } }

Replies are listed 'Best First'.
Re: Creating dynamic Tk buttons??
by converter (Priest) on Jun 06, 2003 at 17:23 UTC
    $buttons-Button(...)->pack(...) allocates and packs a new Tk::Button widget. If you want to replace existing Button widgets, you can invoke the destroy method against each existing Button's reference. If you think the number of Buttons will remain constant during run-time, allocate the Buttons once, then invoke the configure method (see perldoc Tk::options) against each button to change its attributes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://263654]
Approved by kelan
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found