Mobilization

by Joel Limardo

Software Developer and IT Professional

Chicago, IL

joel@joellimardo.com

SIP Phone (researching...)

Workadventure Workadventure (researching...)


Downstream Project Status

BixChange

33%

LIMSExpert.com

28%

Upstream Projects

Joellimardo.com Project Cleanup




Wed, 17 Jan 2024

GUIs in Perl

Have to start with Perl/Tk simply because it was the first one I started working with. Also, interfaces in Perl/Tk are on the unsightly side **but** look about the same as an Emacs interface so why not put a few things in there?

Super-quick spec of things I want to do:

  • Simple windows using Perl/Tk
  1. Installation
  2. Hello World
  3. Planning

  Up

/technical/upstream/perl/gui Permanent Link Project Sitemap Top  

Form Planning

It is tempting to just start writing code. However, you wind up with a great big mess. Here is PlantUML's Salt that can make the form visualization process go a bit smoother.

  Up

/technical/upstream/perl/gui Permanent Link Project Sitemap Top  

Hello World

There is an online Perl::Tk tutorial I'm going to utilize as well as just the standard Perl::Tk perldocs for these.

#!/usr/bin/perl -w
use Tk;
my $mw = new MainWindow;
$mw->minsize(400,300);
my %formElements = ();
$formElements{'button1Text'} = 'Quit';
$formElements{'label1'} =
$mw -> Label(-text=>"Hello World") -> pack();
$formElements{'button1'} =
$mw -> Button(-textvariable => \$formElements{'button1Text'},
-command => sub { exit })
-> pack();

$formElements{'button2'} =
$mw -> Button(-text => "Change",
-command => sub { $formElements{'button1Text'} = 'Donkey'})
-> pack();
MainLoop;

So here I created a simple form based on one of the site examples but made it a) a better minimum size rather than a very small popup with only a button on it b) added an additional button c) made the second button change the text of the first when pressed.

The standard beginner examples often skip past the fact that you can use -textvariable rather than just text and point that to a variable.

  Up

/technical/upstream/perl/gui Permanent Link Project Sitemap Top