Thread Thread in Tk-Anwendung (5 answers)
Opened by dimpflmoser at 2010-08-23 15:03

Molaf
 2010-08-25 09:02
#140918 #140918
User since
2007-10-11
119 Artikel
BenutzerIn
[default_avatar]
Auf die Tk-Variablen bekommt man auch keinen Zugriff, aber es geht andersrum:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl

use strict;
use warnings;

use threads;
use threads::shared;
use Tk;

my $xxx:shared='';
my $thread = threads->create( \&search_file );
$thread->detach;

my $mw = tkinit();
$mw->Label( -text => 'hallo' )->pack;
$mw->Entry( -textvariable => \$xxx )->pack;

MainLoop;

sub search_file {
my $counter = 0;
for (;;) {
$counter++;
$xxx = $counter;
sleep 1;
}
}

Sollen komplexere Dinge mit dem Tk gemacht werden, füge ich immer ein repeat ein und mache das im Hauptprogramm/-thread, indem ich auf die mitbenutzten Variablen zugreife.

Molaf

View full thread Thread in Tk-Anwendung