Tk continues to amaze and confound me, today I have tried to create an interface where I can 'stroll' through records selected from a database table.
Here is a stripped down version of my package. As you can see the data to be displayed (and ultimately edited) is stored in a hash within the module. My problem is that if the _get_records_all method is called after the draw mthod has been called the data is not displayed.
What fundamental error have I made here? I hope someone can help!
package contact; use strict; use Tk; use Tk::BrowseEntry; use Data::Dumper; use InContact::cDBI; sub new { my ($self, %arg) = @_; bless { _nbpage => $arg{nbpage}, _record => $arg{record}, _iter => '', _iter_cnt => 0, _iter_index => 0, _ft => '', }, $self } sub draw { my ($self) = @_; my $fs = $self->{_nbpage}->Frame( -borderwidth => 2, -relief => 'groove', )->pack; $fs->Button( -text => 'All', -command => sub { $self->_get_records_all }, )->grid( $fs->Button( -text => 'Today', -command => sub { exit }, ), -sticky => 'w', -padx => 2, -pady => 2 ); $self->{_ft} = $self->{_nbpage}->Frame( -borderwidth => 2, -relief => 'groove', )->pack; $self->{_ft}->Label(-text => 'Contact ID' )->grid( $self->{_ft}->Entry( -textvariable => \$self->{_record}->{id +}, ), -sticky => 'w', -padx => 2, -pady => 2 ); $self->{_ft}->Label( -text => 'First Name' )->grid( $self->{_ft}->Entry( -textvariable => \$self->{_record}->{fi +rstname}, ), $self->{_ft}->Label( -text => 'Last Name' ), $self->{_ft}->Entry( -textvariable => \$self->{_record}->{la +stname}, ), $self->{_ft}->Label( -text => 'Company', ), $self->{_ft}->Entry( -textvariable => \$self->{_record}->{co +mpany}, ), -sticky => 'w', -padx => 2, -pady => 2 ); }
updated: removed some irrelevant code.# _get_records_all # get all records and pass the first to the display sub _get_records_all { my $self = shift; $self->{_iter} = InContact::cDBI::contact->retrieve_all(); $self->{_iter_cnt} = $self->{_iter}->count(); $self->{_iter_index} = 0; my $obj = $self->{_iter}->first; $self->{_record} = $obj->hashy; print Dumper $self->{_record}; return; } 1;
In reply to Perl/Tk - Can't see data? by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |