1. You cannot spawn a thread from a Tk Button callback.
2. You cannot access a Tk widget from a thread.
Here is some code to show you how to use shared variables and Tk with threads. I don't use win32, so OLE stuff is left out and may be a bigger problem yet.
#!/usr/bin/perl use strict; use warnings; use Tk; use threads; use threads::shared; my $data:shared = ''; my $go_control:shared = 0; my $die_control:shared = 0; #create thread before any Tk my $thr = threads->new(\&excecute); my $mainWindow = MainWindow->new; my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7, -scrollbars=>"ose", -wrap=>"word")->pack(); my $goBut; # need to declare here so can be used in -command $goBut = $mainWindow->Button(-foreground=>"blue", -text=>"Click", -command=>sub { $goBut->configure(-state=>"disabled +"); $textBox->configure(-state=>"normal"); $go_control = 1; #start thread } )->pack(); my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Exit", -command=>sub{ $die_control = 1; $thr->join; exit; })->pack(); #use a timer to read the shared variable and deal with Tk stuff my $repeater = $mainWindow->repeat(20,sub{ $textBox->insert('end',$data); $textBox->see('end'); }); MainLoop; sub excecute{ # require Win32::OLE; # require Win32::OLE::Const 'Microsoft Excel'; while(1){ #wait for $go_control if($go_control){ open(FILE,$0 ) or die "Can't open file.\n"; while(<FILE>){ if($die_control){return} $data = $_; } close(FILE); }else{ select(undef,undef,undef,.25); }# sleep until awakened } return; }
In reply to Re: Tk & threads & Excel OLE??
by zentara
in thread Tk & threads & Excel OLE??
by Slickuser
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |