use Tk; use Tk::DBI::Table; my $dbh = createDBconnection(); my $SQL = qq~SELECT * FROM mytable~; my $window = doDBItable( $dbh, $SQL, 'My display window' ); sub doDBItable { my ( $dbh, $SQL, $title ) = @_; if ( not defined $title ) { $title = "List Preview" } my $top = MainWindow->new( -title => $title ); $top->geometry("600x400+50+50"); my $tkdbi = $top->DBITable( -sql => $SQL, -dbh => $dbh, -display_id => 0, -debug => 0, )->pack( -expand => 1, -fill => 'both' ); debug("-doDBItable"); return $top; } sub createDBconnection { use DBI; my %attr = ( PrintError => 0, RaiseError => 0. ); if ( my $dbh = DBI->connect( 'DBI:mysql:mydatabase', 'username', 'password', \%attr ) ) { return ($dbh); } else { print "Cannot open MySQL connection: " . DBI::errstr() . "\n"; return 0; } }