#!/usr/bin/perl use strict; use warnings; use Tk; use DBI; use DBD::mysql; our $type="mysql"; our $database="store"; our $host="somesite.com"; our $port="3306"; our $tablename="vegetables"; our $user="example"; our $pwd="*********"; our $dsn="dbi:$type:$database:$host:$port"; our $query; our $queryhandle; our $connect=DBI->connect($dsn,$user,$pwd) || die "ERROR: $!\n"; my $mw=new MainWindow; $mw->Label(-text=>"Search for vegetables")->pack; # fix misspelled "Lable" my $veges=$mw->Entry()->pack; $mw->Button(-text=>"Search",-command=>\&search)->pack; # Declare a variable and just one Label widget for displaying results: my $result_string; my $results = $mw->Label( -textvariable => \$result_string )->pack; sub search{ my $sv=$veges->get();$veges->delete(qw/0 end/); $query="SELECT count(*) FROM vegetables WHERE vegetable LIKE '%$sv%'"; $queryhandle=$connect->prepare($query); $queryhandle->execute; my ( $hit_count ) = $queryhandle->fetchrow_array; # there's just one row $result_string = sprintf( "Found %d matches for %s", $hit_count, $sv ); # assigning a new value to $result_string will update the Label display } MainLoop;