Thread GUI in Form von Windows Explorer erstellen
(15 answers)
Opened by
Mampfgnom
at 2010-10-27 15:05
User since 2003-08-07
2921
Artikel
BenutzerIn
Hallo!
Nimm ein Frame, das die beiden Frames, die gleich groß sein sollen, aufnimmt.
Ich baue Progarmme nach Möglichkeit immer in Zeilen auf, damit ich für jede Zeile ein eigenes Frame habe.
Hier das Minimalbeispiel:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/perl
use strict; use warnings; use Tk;
my $mw = tkinit();
my $parent_frame = $mw->Frame()->pack(-fill => 'both', -expand => 1,);
my $left = $parent_frame->Frame(-bg => 'red')->pack(-side => 'left', -fill => 'x', -expand => 1,); $left->Button(-text => 'test',)->pack();
my $right = $parent_frame->Frame(-bg => 'blue')->pack(-side => 'left', -fill => 'x', -expand => 1,); $right->Button(-text => 'test',)->pack();
$mw->MainLoop();
Und hier ein anderer Ansatz, mit den verschiedenen Zeilen, einem Menu und deinem LabEntry. Da könntest du ganz gut weiter machen :)
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
#!/usr/bin/perl
package TkApp;
use base qw(Class::Accessor);
use strict; use warnings; use FileHandle; use Data::Dumper qw/Dumper/; use Date::Format; use Tk; use Tk::LabEntry; use Tk::DirTree; use Tk::HList;
__PACKAGE__->follow_best_practice(); __PACKAGE__->mk_accessors(qw(mw graph));
our $VERSION = 0.1;
=head1 NAME
TkApp - experimental layout
=head1 SYNOPSIS
use strict; use warnings; my $app = TkApp->new(); $app->run();
=head1 DESCRIPTION
- menu - entry box - two areas with equal size
=head2 EXPORT
None by default.
=head1 METHODS
=head2 new()
Ctor. Calls _build_gui.
=cut
sub new { my $class = shift; my $self = bless({}, $class); my $mw = Tk::MainWindow->new(); $self->set_mw($mw); $self->_build_gui(); return $self; } # /new
=head2 _build_gui()
Build GUI. Set up widgets etc. Positioning is done here, too.
Private method. Don't call it directly, as this will be done by new().
=cut
sub _build_gui { my $self = shift; my $mw = $self->get_mw(); my %gui = ();
# -- menu my $menuitems = [ [Cascade => "~File", -menuitems => [ [Button => "Some ~Method", -command => sub{ return $self->some_method(); }], [Separator => ""], [Button => "~Exit", -command => sub{ exit(0); }], ], ], ]; my $menu = $mw->Menu(-menuitems => $menuitems); $mw->configure(-menu => $menu);
# define & pack your widgets here $gui{f_selectors} = $mw->Frame(-bg => 'green')->pack(-fill => 'x'); $gui{f_selectors}->LabEntry( -label=>"Abaqus Materialverzeichnis", -labelPack=>[-side=>'right'], -width=>80, -text => 'TODO: initial value', )->pack(-padx => 20, -pady => 5); $gui{f_row2} = $mw->Frame( -bg => 'yellow' )->pack(-fill => 'both', -expand => 1,); $gui{f_left} = $gui{f_row2}->Frame( -bg => 'red', )->pack( -side => 'left', -fill => 'both', -expand => 1, ); $gui{f_left}->Label(-text => 'test')->pack(); $gui{f_right} = $gui{f_row2}->Frame( -bg => 'blue', )->pack( -side => 'right', -fill => 'both', -expand => 1, ); } # /_build_gui
=head2 run()
This actually starts the application, including the gui event loop.
=cut
sub run { my $self = shift; my $mw = $self->get_mw(); $mw->MainLoop(); } # /run
=head1 SEE ALSO
Inspired by a thread at L<http://www.perl-community.de>.
=head1 AUTHOR
todo
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by todo
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
=cut
1;
use strict; use warnings;
my $app = TkApp->new(); $app->run();
View full thread GUI in Form von Windows Explorer erstellen
|