Schrift
[thread]5302[/thread]

Beschriftung von Buttons

Leser: 2


<< >> 6 Einträge, 1 Seite
Gast Gast
 2007-03-05 23:50
#46252 #46252
Ich habe in einem Formular folgenden Button:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
$button1 = $mw->Button( -text => "Zeile1\nZeile2",
-relief => "raised",

-font => "{Arial} 24 {bold}",

-background => "#FFFF00",

-activebackground => "#FFFF00",
-command => sub { }
)->place( -x => 55, -y => 50, -height => 100, -width => 200);


Die Beschriftung des Buttons ist zweizeilig durch das \n.

Jetzt möchte ich den Namen des Buttons über eine Variable einfügen. Das habe ich wie folgt gelöst:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
$beschriftung = "Zeile1\nZeile2";
$button1 = $mw->Button( -text => $beschriftung,
-relief => "raised",

-font => "{Arial} 24 {bold}",

-background => "#FFFF00",

-activebackground => "#FFFF00",
-command => sub { }
)->place( -x => 55, -y => 50, -height => 100, -width => 200);


Leider erfolgt dann aber die Beschriftung in einer Zeile mit dem \n lesbar dazwischen.

Gibt es eine Möglichkeit die Beschriftung so einzusetzen das der Zeilenumbruch interpretiert wird?
renee
 2007-03-06 10:30
#46253 #46253
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Welches Perl? Welches Tk? Bei mir funktioniert es auf Solaris, Perl 5.8.6, Tk 800.025
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
 2007-03-06 11:04
#46254 #46254
User since
2004-08-18
463 Artikel
BenutzerIn

user image
Ich nutze Perl V 5.8.8 und TK 804.027-r6

Ich habe es so vereinfacht wie ich es oben gepostet habe nochmal versucht und es klappt wirklich. In meinem Programm wird der Text aber nicht einfach einer Variable zugewiesen sondern aus einer Ini-Datei eingelesen.

Mit folgender Routine lese ich es ein:
Code: (dl )
1
2
3
4
5
6
7
use IniConf;
sub readini
{
my $cfg = IniConf->new( -file => $_[2] );
my $value = $cfg->val($_[0], $_[1]);
return $value;
}


und mit diesem Aufruf wird der Button generiert:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
$button1 = $mw->Button( -text => readini(NAMEN, NAME1, 'text.ini'),
-relief => "raised",

-font => readini(SCHRIFT, FONT, 'text.ini'),

-background => "#FFFF00",

-activebackground => "#FFFF00",
-command => sub { &print; }


}
)->place( -x => 55, -y => 50, -height => 100, -width => 200);


in der InI-Datei steht dann folgendes:
Code: (dl )
1
2
3
4
5
[NAMEN]
NAME1=Zeile1\nZeile2

[SCHRIFT]
FONT={Arial} 12 {bold}
Kean
 2007-03-06 11:07
#46255 #46255
User since
2004-08-18
463 Artikel
BenutzerIn

user image
Der String verhält sich also wie wenn ich ihn mit $text='zeile1\nzeile2'; einlesen würde anstelle von $text="zeile1\nzeile2";.

Ich bräuchte also eine Funktion welche den Inhalt des Strings interpretiert ausgibt. Denke ich mal :p
renee
 2007-03-06 11:26
#46256 #46256
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Das hättest Du gleich sagen sollen ;-)

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
$button1 = $mw->Button( -text => readini(NAMEN, NAME1, 'text.ini'),
-relief => "raised",

-font => readini(SCHRIFT, FONT, 'text.ini'),

-background => "#FFFF00",

-activebackground => "#FFFF00",
-command => sub { &print; }


}
)->place( -x => 55, -y => 50, -height => 100, -width => 200);


=>

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(my $text = readini(NAMEN, NAME1, 'text.ini')) =~ s/\\n/\n/g;

$button1 = $mw->Button( -text => $text,
-relief => "raised",

-font => readini(SCHRIFT, FONT, 'text.ini'),

-background => "#FFFF00",

-activebackground => "#FFFF00",
-command => sub { &print; }


}
)->place( -x => 55, -y => 50, -height => 100, -width => 200);
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
 2007-03-06 12:48
#46257 #46257
User since
2004-08-18
463 Artikel
BenutzerIn

user image
Cooooool, funktioniert! Is eigendlich eine ganze simple Idee, da wär ich nie drauf gekommen :D

Vielen Dank!\n\n

<!--EDIT|Kean|1173178125-->
<< >> 6 Einträge, 1 Seite



View all threads created 2007-03-05 23:50.