Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]4816[/thread]

Scrolled Text auslesen

Leser: 2


<< >> 6 Einträge, 1 Seite
Kean
 2004-08-18 15:34
#42488 #42488
User since
2004-08-18
463 Artikel
BenutzerIn

user image
Gibt es eine Möglichkeit einen Scrolled text auszulesen??
Mit get() funzt das ganze nicht.
renee
 2004-08-18 15:46
#42489 #42489
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Das hier funktioniert bei mir:
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
#! /usr/bin/perl

use strict;
use warnings;
use Tk;
use Tk::TextUndo;

my $mw = MainWindow->new();
my $sc = $mw->Scrolled('Text',
-height => '1',
-width => '10',
-scrollbars => 'osoe',
)->pack();
$mw->Button(-text => 'del',-command => \&deleter)->pack();

$sc->insert('end','Test');

MainLoop;

sub deleter{
my $text = $sc->get('1.0','end');
print $text,"\n";
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
Kean
 2004-08-18 15:59
#42490 #42490
User since
2004-08-18
463 Artikel
BenutzerIn

user image
Vielen Dank, das funktioniert. Was wird mit den Parametern '1.0','end' bewirkt?
renee
 2004-08-18 16:09
#42491 #42491
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Der Text wird vom Anfang (index 1.0) bis zum Ende ('end') ausgelesen.

Man kann auch nur Teile eines Textes auslesen (zum Beispiel bestimmte Zeilen...)\n\n

<!--EDIT|renee|1092831023-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
Crian
 2004-08-18 16:16
#42492 #42492
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
Im Gegensatz etwa zum Entry, wo man mit get einfach den gesamten String bekommt, muss man beim Text-Widget angeben, welche Teile des Textes man möchte. Find ich eigentlich blöd, warum gibt man nicht einfach den gesamten Text zurück, wenn keine Aufrufparameter angegeben werden... Naja, ist nur eine Sache, die man wissen mus. =)

'1.0' bedeutet Zeile 1 Zeichen 0 (also b dem ersten Zeichen)
'end' bedeutet ganz hinten

Ein Tipp: Mit perldoc kannst Du Dir auf der Kommandozeile gezielt Infos zu bestimmten Widgets holen, schneller als jedes Nachschlagen im Buch, etwa perldoc Tk::Text. Wenn man dort dann etwa naach get sucht, findet man diesen Abschnitt:

Quote
   *$text*->get(*index1, *?*index2*?)
       Return a range of characters from the text. The return value will be
       all the characters in the text starting with the one whose index is
       *index1* and ending just before the one whose index is *index2* (the
       character at *index2* will not be returned). If *index2* is omitted
       then the single character at *index1* is returned. If there are no
       characters in the specified range (e.g. *index1* is past the end of
       the file or *index2* is less than or equal to *index1*) then an
       empty string is returned. If the specified range contains embedded
       windows, no information about them is included in the returned
       string.


edit renee: es muss perldoc statt erldoc heißen ;)
Was hatte ich denn geschrieben? Ach erldoc *rofl* Danke =)

An anderer Stelle in der Datei heißt es dann

Quote
INDICES
   Many of the methods for texts take one or more indices as arguments. An
   index is a string used to indicate a particular place within a text,
   such as a place to insert characters or one endpoint of a range of
   characters to delete. Indices have the syntax

    base modifier modifier modifier ...

   Where *base* gives a starting point and the *modifier*s adjust the index
   from the starting point (e.g. move forward or backward one character).
   Every index must contain a *base*, but the *modifier*s are optional.

   The *base* for an index must have one of the following forms:

   *line*.*char*
       Indicates *char*'th character on line *line*. Lines are numbered
       from 1
for consistency with other UNIX programs that use this
       numbering scheme. Within a line, characters are numbered from 0. If
       *char* is end then it refers to the newline character that ends the
       line.

   @*x*,*y*
       Indicates the character that covers the pixel whose x and y
       coordinates within the text's window are *x* and *y*.

   end Indicates the end of the text (the character just after the last
       newline).

   *mark*
       Indicates the character just after the mark whose name is *mark*.

   *tag*.first
       Indicates the first character in the text that has been tagged with
       *tag*. This form generates an error if no characters are currently
       tagged with *tag*.

   *tag*.last
       Indicates the character just after the last one in the text that has
       been tagged with *tag*. This form generates an error if no
       characters are currently tagged with *tag*.

   *$widget*
       Indicates the position of the embedded window referenced by
       *$widget*. This form generates an error if *$widget* does not
       reference to an embedded window.

   *imageName*
       Indicates the position of the embedded image whose name is
       *imageName*. This form generates an error if there is no embedded
       image by the given name.

       If the *base* could match more than one of the above forms, such as
       a *mark* and *imageName* both having the same value, then the form
       earlier in the above list takes precedence. If modifiers follow the
       base index, each one of them must have one of the forms listed
       below. Keywords such as chars and wordend may be abbreviated as long
       as the abbreviation is unambiguous.

   + *count* chars
       Adjust the index forward by *count* characters, moving to later
       lines in the text if necessary. If there are fewer than *count*
       characters in the text after the current index, then set the index
       to the last character in the text. Spaces on either side of *count*
       are optional.

   - *count* chars
       Adjust the index backward by *count* characters, moving to earlier
       lines in the text if necessary. If there are fewer than *count*
       characters in the text before the current index, then set the index
       to the first character in the text. Spaces on either side of *count*
       are optional.

   + *count* lines
       Adjust the index forward by *count* lines, retaining the same
       character position within the line. If there are fewer than *count*
       lines after the line containing the current index, then set the
       index to refer to the same character position on the last line of
       the text. Then, if the line is not long enough to contain a
       character at the indicated character position, adjust the character
       position to refer to the last character of the line (the newline).
       Spaces on either side of *count* are optional.

   - *count* lines
       Adjust the index backward by *count* lines, retaining the same
       character position within the line. If there are fewer than *count*
       lines before the line containing the current index, then set the
       index to refer to the same character position on the first line of
       the text. Then, if the line is not long enough to contain a
       character at the indicated character position, adjust the character
       position to refer to the last character of the line (the newline).
       Spaces on either side of *count* are optional.

   linestart
       Adjust the index to refer to the first character on the line.

   lineend
       Adjust the index to refer to the last character on the line (the
       newline).

   wordstart
       Adjust the index to refer to the first character of the word
       containing the current index. A word consists of any number of
       adjacent characters that are letters, digits, or underscores, or a
       single character that is not one of these.

   wordend
       Adjust the index to refer to the character just after the last one
       of the word containing the current index. If the current index
       refers to the last character of the text then it is not modified.

       If more than one modifier is present then they are applied in
       left-to-right order. For example, the index ``end - 1 chars'' refers
       to the next-to-last character in the text and ``insert wordstart - 1
       c'' refers to the character just before the first one in the word
       containing the insertion cursor.



Dann weiß man wirklich so ungefähr alles ;-)\n\n

<!--EDIT|Crian|1092832729-->
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite
ptk
 2004-08-18 16:47
#42493 #42493
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
[quote=Crian,18.08.2004, 14:16]Im Gegensatz etwa zum Entry, wo man mit get einfach den gesamten String bekommt, muss man beim Text-Widget angeben, welche Teile des Textes man möchte. Find ich eigentlich blöd, warum gibt man nicht einfach den gesamten Text zurück, wenn keine Aufrufparameter angegeben werden... [/quote]
Das waere tatsaechlich eine Frage in comp.lang.tcl oder einen Feature-Request-Eintrag auf der Tcl/Tk-Sourceforge-Seite wert.
<< >> 6 Einträge, 1 Seite



View all threads created 2004-08-18 15:34.