Interapplication Communication

You can use the send command to have Perl/Tk (and even Tcl/Tk) applications communicate back and forth. The arguments include an application to talk to and the command to execute in that application.

$widget->send("application" => callback);

You can also specify the option -async, which will return control immediately instead of waiting for the callback to execute. For complete details, see Chapter 20.

By default, your application will return an error to another application trying to communicate with it. If you want to actually receive communications from other applications, define Tk::Receive($widget, "command") and be careful what you do with the command string. Allowing any application to send unknown commands to your application can be dangerous. Use the interps method to get a list of valid application names.

When engaging in interapplication communication, it is a good idea to run your Perl script with the -T switch, which forces taint checking. Again, see Chapter 20 for complete details and working programs.

Get Mastering Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.