Tk::FormUI - A Moo based object oriented interface for creating forms for use with Tk
Version 1.07
use Tk::FormUI; my $form = Tk::FormUI->new; ## Add an Entry field for text $form->add_field( key => 'user_name', label => 'User name', type => $Tk::FormUI::ENTRY, width => 40, default => 'John Doe', ); ## Add a Radio Button field $form->add_field( key => 'gender', label => 'Gender', type => $Tk::FormUI::RADIOBUTTON, choices => [ { label => 'Male', value => 'male', }, { label => 'Female', value => 'female', }, ], ); ## Display the form and capture the data returned my $data = $form->show;
The Tk::FormUI recognizes the following values for the "type" key when adding or defing a field.
A Tk::Entry widget
CONSTANT: $Tk::FormUI::ENTRY
A group of Tk::CheckButton widgets that correspond to the choices
CONSTANT: $Tk::FormUI::CHECKBOX
A group of Tk::RadioButton widgets that correspond to the choices
CONSTANT: $Tk::FormUI::RADIOBUTTON
A Tk::BrowserEntry widget with a drop-down list that correspond to the choices
CONSTANT: $Tk::FormUI::COMBOBOX
A Tk::Entry widget with a button that will open a Tk::chooseDirectory window
CONSTANT: $Tk::FormUI::DIRECTORY
Title of the form.
DEFAULT: 'Form'
Message to display at the top of the form.
DEFAULT: ''
Font to use for the form's message
DEFAULT: 'times 12 bold'
The fields contained in this form.
The text to appear on the button at the bottom of the form.
You may place the ampersand before the character you want to use as a "hot key" indicating holding the Alt key and the specified character will do the same thing as pressing the button.
DEAULT: '&OK'
Font to use for the form's button.
DEFAULT: 'times 10'
Minimum width of the form window.
DEFAULT: 300
Minimum height of the form window.
DEFAULT: 80
Boolean value indicating if pressing the Enter key should simulate clicking the button to submit the form.
DEFAULT: 1
Boolean value indicating if pressing the Escape key should simulate closing the window and canceling the form.
Font to use for the form's error messages.
String used to indicate an error
DEFAULT: '!'
Font color to use when displaying error message and error marker
DEFAULT: 'red'
Add a field to the form.
A list of key / value pairs should be provide
type - Type of field key - Key to use in hash returned by the show() method label - Text to display next to the field readonly - Boolean indicating if field is read only and cannot be modified choices - ARRAY reference containing hashes that define the possible values for the field. REQUIRED for Checkbox, RadioButton, and Combobox Each hash must have the following key/value pairs label - String to be displayed value - Value to return if selected
UNDEF on error, or the field object created
Show the form as a child of the given parent, or as a new MainWindow if a parent is not specified.
The function will return if the users cancels the form or submits a form with no errors.
$parent - Parent window, if none is specified, a new MainWindow will be created
UNDEF when canceled, or a HASH reference containing whose keys correspond to the key attributes of the form's fields
Once the user submits or cancels the form, the function will return.
initialize the form from a HASH reference, JSON string, or JSON file. In all cases, the hash should have the following format
{ title => 'My Form', fields => [ { type => 'Entry', key => 'name', label => 'Name', }, { type => 'Radiobutton', key => 'sex', label => 'Gender', choices => [ { label => 'Male', value => 'male', }, { label => 'Female', value => 'female', }, ], } ] }
$param - HASH reference, or scalar containin JSON string, or filename
NONE
Use the key/values of the provided hash to set the corresponding field values
$hash - Hash reference containing key /values whose keys correspnd to the various field keys
Clear errors on all form fields
Return the field associated with the provided key or UNDEF if not found.
$key - The key associated with the desired field
UNDEF if not found, or a Tk::FormUI field object
Set the error for the field associated with the given key
$error - Error message for the given field
Returns TRUE if any field in the form has an error
TRUE if any field has an error
Paul Durden <alabamapaul AT gmail.com>
Copyright (C) 2015 by Paul Durden.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tk::FormUI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tk::FormUI
CPAN shell
perl -MCPAN -e shell install Tk::FormUI
For more information on module installation, please visit the detailed CPAN module installation guide.