When you say "sometimes it won't load", does that really mean that sometimes "it does load"? If "sometimes it works" and "sometimes it doesn't", the possible explanations include: I'm guessing that the third one is most likely what is really going on. Here's a slightly modified version of your script that might get you headed in the right direction:
#!/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 "L +able" 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 o +ne row $result_string = sprintf( "Found %d matches for %s", $hit_count, $ +sv ); # assigning a new value to $result_string will update the Labe +l display } MainLoop;
When you want to show an actual list of rows that are returned by a query, try using a Listbox or Text widget, something that can hold all the results in a single scrollable object.

(As posted, your script creates a new Label widget for every row in the query result, so if the first query returns 50 rows, you get 50 Labels stacked vertically that all say the same thing. That's pretty useless - once the window expands to the bottom of the screen, you can see anything else, and those first 50 labels never go away, so you'll never see results from a second or third query.)


In reply to Re: Perl/Tk hang when conecting to Remote MySQL Server by graff
in thread Perl/Tk hang when conecting to Remote MySQL Server by Muskovitz

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.