Tk with Thread

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am currently using perl, v5.8.8 built for MSWin32-x86-multi-thread.

I have a Button on my GUI, when I pressed the button. It will parse
some file.
The parsing will run but my GUI will freeze. Once it's done parsing, I
can control my GUI again.

Is there a way to use Thread so my parsing is running and I can still
use my GUI?

I was looking at

But it doesn't work for me. I also try 'threads' as well.

Any help?

Re: Tk with Thread

Quoted text here. Click to load it

A straightforward way around this is to call $mainwindow->update
periodically during the processing. This can, however, be a little
tricky to arrange, depending on what the parsing consists of.

Quoted text here. Click to load it

Don't use Thread. It was part of the old 5005threads model that came
with 5.5; in 5.8 it is just a pass-through for threads.

Quoted text here. Click to load it

It's best to read the documentation that comes with your version of
perl. That page appears to belong with 5.6.0: a lot has changed since
then, particularly wrt threads.

Quoted text here. Click to load it

'Doesn't work' is not a helpful problem description. Please reduce your
program to a minimal example (preferably just a Tk window with a single
button, and a sub that calls something like 'sleep 500' to simulate the
parsing) and post it. Also describe what it is doing that you don't

Tk will work in multithreaded programs, but be sure to only access the
Tk objects from one thread. Tk itself isn't threadsafe.


And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * *

Re: Tk with Thread

So I should used threads and not Thread?

Also, I look at fork. Will this help me?


Quoted text here. Click to load it

Re: Tk with Thread

On Wed, 14 May 2008 16:57:37 -0700 (PDT), Slickuser

Quoted text here. Click to load it

Here is a general purpose example. It creates threads before any
Tk is called, to be thread-safe. It creates a pool of 3 reusable
worker-threads, but you can cut down the complexity by using
just onw thread.

You can also try the Tk::ExecuteCommand module.

#!/usr/bin/perl -w
use Tk;
use Tk::ExecuteCommand;
use Tk::widgets qw/LabEntry/;
use strict;

my $mw = MainWindow->new;

my $ec = $mw->ExecuteCommand(
    -command    => '',
    -entryWidth => 50,
    -height     => 10,
    -label      => '',
    -text       => 'Execute',
$ec->configure(-command => 'date; sleep 10; date');

my $button = $mw->Button(-text =>'Do_it',
                         -background =>'hotpink',
                         -command => sub{ $ec->execute_command },

I'm not really a human, but I play one on earth.

Site Timeline