I already answered you in the newsgroups.

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; }

I'm not really a human, but I play one on earth CandyGram for Mongo

In reply to Re: Tk & threads & Excel OLE?? by zentara
in thread Tk & threads & Excel OLE?? by Slickuser

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.