As some of you probably know, I've been working on a Win32 application now for a couple days using Tk for the GUI interface. I finally have everything working aside from updating my Entry fields. The way my script is working, I build the window with all fields. Once one field is filled out and a button is pressed, it filles the remaining fields from a database. Pretty simple to be honest. However, for some reason I can not get those Entry boxes to fill. I've seen varrious ways to fill them such as using
. However, i have been thus far completely unsuccessful at getting them to update. In fact, I don't seem to be able to add text to the Entry Boxes when I first build them. If you would like to give me a hand here and let me know what I'm doing wrong, I would appreciate it. My code minus the irrelevant subroutines is below.
use strict;
use Tk 800.00;
use Mysql;
require Tk::Frame;
require Tk::TextUndo;
require Tk::Text;
require Tk::Scrollbar;
require Tk::Menu;
require Tk::Menubutton;
require Tk::Adjuster;
require Tk::DialogBox;
require Tk::JComboBox;
# Main Window
my $mw = new MainWindow;
$mw->geometry('800x600');
# Frames Setup
my $lf = $mw->Frame->pack(qw/-side left -fill y/);
my $rf = $mw->Frame->pack(qw/-side right -fill y/);
# Menu Bar Setup
my $mb = $mw->Menu(-menuitems => &menubar_menuitems() );
$mw->configure(-menu => $mb);
$mw->title("INSCO Inventory Control");
#Set Up Client Information
my %field;
my @names = (qw/po client contact phone email address city state zip i
+d model/);
my @labls = ("PO:", "Client:", "Contact:", "Contact Phone Number:", "C
+ontact Email Address:", "Contact Post Address:", "", "" , "", "Client
+ Specified ID", "Model");
my @position = (1,2,3,4,5,6,7,8,9,10,11);
foreach (@names) {
my $position = int(shift(@position));
$field{$_}{txvar} = '';
$field{$_}{label} = $rf->Label(
-text => shift( @labls ))
->grid(-row => $position,
-col => '0',
);
}
my $current_city = "San Juan";
my $tf_po = $rf->Entry(-width=>30, -textvariable=>'current_po')->
+grid(-row => '1', -col => '2');
my $tf_client = $rf->Entry(-width=>30, -textvariable=>'current_client
+')->grid(-row => '2', -col => '2');
my $tf_contact = $rf->Entry(-width=>30, -textvariable=>'current_contac
+t')->grid(-row => '3', -col => '2');
my $tf_phone = $rf->Entry(-width=>30, -textvariable=>'current_phone'
+)->grid(-row => '4', -col => '2');
my $tf_email = $rf->Entry(-width=>30, -textvariable=>'current_email'
+)->grid(-row => '5', -col => '2');
my $tf_address = $rf->Entry(-width=>30, -textvariable=>'current_addres
+s')->grid(-row => '6', -col => '2');
my $tf_city = $rf->Entry(-width=>30, -textvariable=>'current_city')
+->grid(-row => '7', -col => '2');
my $tf_state = $rf->Entry(-width=>30, -textvariable=>'current_state'
+)->grid(-row => '8', -col => '2');
my $tf_zip = $rf->Entry(-width=>30, -textvariable=>'current_zip')-
+>grid(-row => '9', -col => '2');
my $tf_id = $rf->Entry(-width=>30, -textvariable=>'current_id')->
+grid(-row => '10', -col => '2');
my $tf_model = $rf->Entry(-width=>30, -textvariable=>'current_model'
+)->grid(-row => '11', -col => '2');
#Set Up Serial Query Information
my $label_input = $lf->Label(-text=>'Serial Number: ',)->pack(qw/-si
+de top/);
my $tf_serial = $lf->Entry(-width=>30)->pack(qw/-side top/);
my $label_space = $lf->Label(-text=>'',)->pack(qw/-side top/);
my $returned = "";
my $current_client = "hello world";
my $button_submit = $lf->Button(
-text => 'Search',
-command => sub{get_data($tf_client,$tf_contact,$tf_phone,$tf_emai
+l,$tf_address,$tf_city,$tf_state,$tf_zip,$tf_id,$tf_model)}
)->pack;
my $spacer0 = $rf->Label(-text => '')->grid(-row => 12, -col => 1);
my $spacer1 = $rf->Label(-text => '')->grid(-row => 13, -col => 1);
my $jcb_experiments = $rf->JComboBox(
-relief => 'groove',
-popuprelief => 'groove',
-highlightthickness => 0,
-choices => ''
)->grid(-row => 14, -col => '5');
$jcb_experiments->removeAllItems();
my $jcb_employees = $rf->JComboBox(
-relief => 'groove',
-popuprelief => 'groove',
-highlightthickness => 0,
-choices => ''
)->grid(-row => 14, -col => '7');
$jcb_employees->removeAllItems();
# Set up Labs Menu
my $label_labs = $rf->Label(-text => 'Lab:', -width => '10')->grid(-ro
+w => 14, -col => 1);
my @labs = get_labs();
my $jcb_labs = $rf->JComboBox(
-relief => 'groove',
-popuprelief => 'groove',
-highlightthickness => 0,
-choices => '',
-scmd => sub{ get_employees(), get_experiments();}
)->grid(-row => 14, -col => '2');
foreach(@labs){
$jcb_labs->addItem($_);
}
$jcb_labs->setSelectedIndex(0);
# Set Up Experiements Menu
my $label_experiments = $rf->Label(-text => 'Experiments:')->grid(-row
+ => 14, -col => 3);
my $label_employees = $rf->Label(-text => 'Employee:')->grid(-row => 1
+4, -col => 6);
my $button_load_up = $rf->Button(
-text => 'Place Work Order',
-command => \&place_order,
-state => 'disabled'
)->grid(-row=>17, -col =>3);
my $status = $tf_po->get;
if($status ne ""){
$button_load_up->configure(-state => 'active');
}
MainLoop;
exit 0;
sub get_data {
my ($tf_client,$tf_contact,$tf_phone,$tf_email,$tf_address,$tf_cit
+y,$tf_state,$tf_zip,$tf_id,$tf_model) = @_;
my $entered = $tf_serial->get;
my $dbh = Mysql->connect("localhost", "insco_inventory", "INSCO",
+"******") or
die("Could Not Connect To Server");
my $query = qq~SELECT * FROM inventory WHERE serial='$entered'~;
my $sth = $dbh->query($query);
my @arr = $sth->fetchrow;
my $current_client = "hello world";
}
sub get_employees {
my $index = $jcb_labs->getSelectedIndex();
my $lab = $jcb_labs->getItemNameAt($index);
my $dbh = Mysql->connect("localhost", "insco_inventory", "INSCO",
+"******") or
die("Could Not Connect To Server");
my $query = qq~SELECT name FROM employees WHERE lab='$lab' ORDER B
+Y workload~;
my $sth = $dbh->query($query);
my @arr;
my @return_vals;
while(@arr = $sth->fetchrow) {
push(@return_vals,$arr[0]);
}
$jcb_employees->removeAllItems();
foreach(@return_vals){
$jcb_employees->addItem($_);
}
$jcb_employees->setSelectedIndex(0);
}
sub get_labs {
my $dbh = Mysql->connect("localhost", "insco_inventory", "INSCO",
+"******") or
die("Could Not Connect To Server");
my $query = qq~SELECT * FROM labs~;
my $sth = $dbh->query($query);
my @arr;
my @return_vals;
while(@arr = $sth->fetchrow) {
push(@return_vals,$arr[1]);
}
return(@return_vals);
}
sub get_experiments {
my $index = $jcb_labs->getSelectedIndex();
my $lab = $jcb_labs->getItemNameAt($index);
my $dbh = Mysql->connect("localhost", "insco_inventory", "INSCO",
+"hernagra") or
die("Could Not Connect To Server");
my $query = qq~SELECT tests FROM labs WHERE name='$lab'~;
my $sth = $dbh->query($query);
my $arr = $sth->fetchrow;
my @return_vals;
my @experiments = split(/\|/, $arr);
foreach(@experiments){
push(@return_vals,$_);
}
$jcb_experiments->removeAllItems();
foreach(@return_vals){
$jcb_experiments->addItem($_);
}
$jcb_experiments->setSelectedIndex(0);
}
Edit by tye, title, add READMORE