Thread Entry & Scale via -textvariable: Problem... (15 answers)
Opened by pktm at 2005-08-12 05:16

pktm
 2005-08-12 16:42
#44352 #44352
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
So, kurz gesagt: Es geht nicht!

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/Perl/bin/perl

use strict;
use warnings;
use Tk;
use Tk::Scale;
use Tk::Balloon;
use Tk::NumEntryPlain;
use Tk::EntryCheck;
use Tk::NumEntry;

my $mw = Tk::MainWindow->new(-width=>150,-height=>150,);
$mw->gridPropagate(0);
$mw->packPropagate(0);

my $wert = 10;

my $s = $mw->Scale(
-variable => \$wert,
-from => 0,
-to => 100,
-length => 50,
-showvalue => 0,
-sliderlength => 6,
-sliderrelief => 'raised',
-orient => 'horizontal',
);

my $e = $mw->NumEntry(
-minvalue => 0,
-maxvalue => 100,
-width => 5,
-bell => 1,
-text => $wert,
);

my $l = $mw->Label(
-textvariable => \$wert,
);

# ------------ configure

$e->configure(
-validate => 'key',
-vcmd => sub{
if( main::setScale($e, $s) ){
return 1;
}else{
return 0;
}
},
);

$s->configure(
-command => sub{
main::setEntry($e, $s, \$wert);
},
);

$e->pack();
$s->pack();
$l->pack();

Tk::MainLoop;

sub setScale {
my ($e, $s) = @_;
# ist Wert ist auf jeden Fall numerisch
# $wert ist bereits durch -variable gesetzt
$e->configure(-text=>$wert);
return 1;
} # /setScale

sub setEntry {
my ($e, $s, $wert_ref) = @_;

# $zw kann "" sein
my $zw = $e->get();
if( $zw =~ m/.{0,0}/ ){
$zw = 0;
}
$$wert_ref = $zw;
$s->set($zw);
} # /setScale


Entweder bin ich einfach zu dumm um die Tk-Callbacks zu nutzen oder Tk ist zu dumm.
Aber wenn das so weiter geht lege ich mir einen Timer zu der alle 500ms die das Entry-Feld ausliest und bei Abweichung die Scale ändert (andersherum ist es kein Problem, -command bei funktioniert ja).

Kann man denn nicht einfach erzwingen, dass eine Methode bei jeglicher Input-Modifikation eines Entrys ausgeführt wird?
-validate = >'all' funktioniert bei mri nicht (um genau zu sein wird es manchmal 2mal, manchmal aber auch nur einmal ausgeführt und dann nicht mehr).

Geht sowas eventuell mit bind?

Grüße, pktm
http://www.intergastro-service.de (mein erstes CMS :) )

View full thread Entry & Scale via -textvariable: Problem...