Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello Monks

I need to monitor if a new element has been programmatically added to a Listbox. If a new element has been added, a subroutine should be called. Since I am not aware of any callback for this, in the script below, I try to use programmatically select a Listbox element with selectionSet (whenever a new element is added) in order to let the <<ListboxSelect>> call a subroutine. The approach does not work, since <<ListboxSelect>> seems to be called only if a Listbox element is selected by the user. Using <<Modified>> does not work too.

Any suggestion on how I could solve this?

use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $lbox = $mw->Listbox()->pack(); my @list = ( "a", "b", "c", "d", "e", "f" ); $lbox->insert('end', @list ); $lbox->selectionSet('1'); #$mw->Button(-text => "Set!", -command=>sub{$lbox->selectionSet('2');} +)->pack();#to test if sectionSet works with <<ListboxSelect>> $lbox->bind('<<ListboxSelect>>', sub{warn "ListBox changed\n"} ); $mw->MainLoop;

EDIT

The code above is in Perl/Tk and not in Tcl::Tk simply because I was looking for a solution independently of Tcl::Tk, as I thought a callback triggered by a state change in the Listbox was easier/possible to achieve then working on the Tcl bridge to Perl through Tcl::Tk (or the similar Tcl::pTk)


In reply to Tk (Tcl::Tk) programmatically monitor change in Listbox by IB2017

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 having a coffee break in the Monastery: (7)
As of 2024-04-18 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found