Esteemed Monks,

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 ); }
# _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;
updated: removed some irrelevant code.

In reply to Perl/Tk - Can't see data? by jdtoronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.