perlunity.de - PERL | JAVASCRIPT | PHP | MySQL | APACHE



#!/COMMUNITY

Members: 5374
davon online: 1
weitere User: 29
Click for quality!




11.02.2012 / 17:01

Community-Member werden   |   Paßwort vergessen   |   OnlineMonitor (1) Wer ist online ... OnlineMonitor starten !
     

 

Home


PERLscripts


PHPscripts


JAVAscripts


Hilfreiches


Links2www


Newscenter


Community


Interna




Community  »  Perl: Allgemeines Forum zur Themenübersicht Themensuche Themenansicht in Thread-Modus


BeitragPerl/TK - Handy-GUI
Seitenanfang
Hallo!

Ich hab da mal ne Frage an euch: Ich soll bis morgen ein TK-Beispiel programmieren, welches ein Handy-GUI sein soll. Wenn man möchte, kann man auch noch nach Belieben erweiterte Funktionalität erstellen, ist aber kein Muss. Die Ausgabe soll über STDOUT erfolgen, sprich im DOS-Fenster angezeigt werden. Mein Beispiel sieht folgendermaßen aus:


# PICHLHÖFER Robert
# 0100549
# N066936

#!/usr/bin/perl

use strict;
use warnings;
use Tk;

# Hauptfenster
my $nw = MainWindow->new();

# Titel des Hauptfensters
$nw->title ('Man-Machine Interfaces II - UE - BSP 3');

# Menü
my $mbar = $nw -> Menu();
$nw->configure (-menu => $mbar);
my $file = $mbar->cascade (-label => "File", -underline => 0, -tearoff => 0);
$file->command (-label => "Exit", -command => [$nw => 'destroy']);

# Buttons
my $b1 = $nw->Button (-text => '1', -command => sub {print "1";}, -height => 5, -width => 5)->pack (-side => 'top');
my $b2 = $nw->Button (-text => '2', -command => sub {print "2";}, -height => 5, -width => 5)->pack (-side => 'top');
my $b3 = $nw->Button (-text => '3', -command => sub {print "3";}, -height => 5, -width => 5)->pack (-side => 'top');
my $b4 = $nw->Button (-text => '4', -command => sub {print "4";}, -height => 5, -width => 5)->pack (-side => 'left');
my $b5 = $nw->Button (-text => '5', -command => sub {print "5";}, -height => 5, -width => 5)->pack (-side => 'left');
my $b6 = $nw->Button (-text => '6', -command => sub {print "6";}, -height => 5, -width => 5)->pack (-side => 'left');
my $b7 = $nw->Button (-text => '7', -command => sub {print "7";}, -height => 5, -width => 5)->pack (-side => 'bottom');
my $b8 = $nw->Button (-text => '8', -command => sub {print "8";}, -height => 5, -width => 5)->pack (-side => 'bottom');
my $b9 = $nw->Button (-text => '9', -command => sub {print "9";}, -height => 5, -width => 5)->pack (-side => 'bottom');
my $b0 = $nw->Button (-text => '0', -command => sub {print "0";}, -height => 5, -width => 5)->pack (-side => 'bottom');

MainLoop();

Im Fenster sollten die Buttons eigentlich so gereiht und gleich groß sein:


1 2 3
4 5 6
7 8 9
0

Wie könnte ich das machen?

Als erweiterte Funktionalität könnte man noch die Sternchen- & Raute-Taste dazugeben bzw. zu jeder Zahl auch die Buchstaben (z. B.: bei 1 wäre dann a b c). Wie könnte ich das denn realisieren? Falls ich die erweiterte Funktionaltität nicht habe, ist es kein Problem, da man es nach Belieben machen kann und daher kein Muss ist.

Vielen lieben Dank für eure Hilfe.

LG,
Robert!

Datum: 10.06.2007-13:32

Beitragre: Perl/TK - Handy-GUI
Seitenanfang

#!/usr/bin/perl

use strict;
use warnings;
use Tk;

# Hauptfenster
my $nw = MainWindow->new();

# Titel des Hauptfensters
$nw->title ('Man-Machine Interfaces II - UE - BSP 3');

# Menü
my $mbar = $nw -> Menu();
$nw->configure (-menu => $mbar);
my $file = $mbar->cascade (-label => "File", -underline => 0, -tearoff => 0);
$file->command (-label => "Exit", -command => [$nw => 'destroy']);

# Frames
my $f1 = $nw->Frame()->pack (-side => 'top', -expand => 1, -fill => 'both');
my $f2 = $nw->Frame()->pack (-side => 'left', -expand => 1, -fill => 'both');
my $f3 = $nw->Frame()->pack (-side => 'bottom', -expand => 1, -fill => 'both');

# Buttons
my $b1 = $f1->Frame (-borderwidth => 3, -relief => 'groove')->pack (-side => 'top', -expand => 1, -fill => 'both');
my @buttonwahl1 = ('1', '2', '3');
for my $a (0..$#buttonwahl1)
{
$b1->Button (-text => $buttonwahl1[$a], -command => sub {print "$buttonwahl1[$a]"})->pack (-anchor => 'e');
}

my $b2 = $f2->Frame (-borderwidth => 3, -relief => 'groove')->pack (-side => 'left', -expand => 1, -fill => 'both');
my @buttonwahl2 = ('4', '5', '6');
for my $b (0..$#buttonwahl2)
{
$b2->Button (-text => $buttonwahl2[$b], -command => sub {print "$buttonwahl2[$b]"})->pack (-anchor => 'e');
}

my $b3 = $f3->Frame (-borderwidth => 3, -relief => 'groove')->pack (-side => 'bottom', -expand => 1, -fill => 'both');
my @buttonwahl3 = ('7', '8', '9', '0');
for my $c (0..$#buttonwahl3)
{
$b3->Button (-text => $buttonwahl3[$c], -command => sub {print "$buttonwahl3[$c]"})->pack (-anchor => 'e');
}

MainLoop();

hier hab ich's noch einmal, aber dieses mal mit frames.

sollte aber trotzdem irgendwie so aussehen, was nicht funktioniert:


1 2 3
4 5 6
7 8 9
0

Datum: 10.06.2007-14:59

Beitragre: Perl/TK - Handy-GUI
Seitenanfang
PerlTk hat 3 unterschiedliche Geometriemanager, der bekannteste und meist verwendetste ist 'pack', neben diesen gibt es noch 'place' (zur genauen Positionierung von Widgets durch Koordinaten) und 'grid' (ordnet die Widgets in einer Art Tabelle an). Da die Anordnung der Tasten einer 3x4-Tabelle entspricht wuerde ich grid verwenden, dabei ist zu beachten dass du 'pack', 'place' und 'grid' nicht mischen darfst, zumindest nicht im gleichen Container-Widget.

Datum: 11.06.2007-12:38

-






-
-