• Publicidad

Duda Gtk

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Duda Gtk

Notapor visualfree » 2009-11-19 16:50 @743

Bueno, amigos, hice el siguiente código...
pero (SOLO ME MUESTRA UN BOTÓN :( ...)
¿Alguien me da una mano?

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl -w
  2.  
  3. use Gtk2 '-init';
  4. $ventana = Gtk2::Window->new('toplevel');
  5. $ventana->set_title('Hello World!');
  6. $ventana->set_border_width(50);
  7. $boton =Gtk2::Button->new('Hello World!');
  8. $boton1 =Gtk2::Button->new('Hola 2');
  9. $ventana->add($boton);
  10. $ventana->add($boton1);
  11.  
  12.  
  13. $ventana->show_all;
  14. # Empieza el show...
  15. Gtk2->main;
  16.  
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
visualfree
Perlero nuevo
Perlero nuevo
 
Mensajes: 41
Registrado: 2009-11-19 03:01 @167

Publicidad

Re: Duda Gtk

Notapor explorer » 2009-11-19 17:06 @754

El mensaje de error es este:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one widget at a time; it already contains a widget of type GtkButton at ./code_19804.pl line 10.
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

Quiere decir que en un objeto GtkBin solo puede contener un widget cada vez. Y ya está ocupado por el primer botón.

Necesitas otro tipo de objeto que pueda almacenar más elementos.

Aquí, por ejemplo, usaré un HBox. Además, aprovecharé para decirle a la ventana qué tiene que hacer cuando deseemos cerrar la ventana pulsando en el botón 'x'.
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl -w
  2.  
  3. use Gtk2 '-init';
  4.  
  5. $ventana = Gtk2::Window->new('toplevel');
  6. $ventana->set_title('Hello World!');
  7. $ventana->set_border_width(50);
  8. $ventana->signal_connect(delete_event => sub {Gtk2->main_quit()});
  9.  
  10. $boton  = Gtk2::Button->new('Hello World!');
  11. $boton1 = Gtk2::Button->new('Hola 2');
  12. #$ventana->add($boton);
  13. #$ventana->add($boton1);
  14.  
  15.  
  16. $box = Gtk2::HBox->new(TRUE,10);
  17. $box->add( $boton);
  18. $box->add( $boton1);
  19.  
  20. $ventana->add($box);
  21.  
  22. $ventana->show_all;
  23.  
  24. # Empieza el show...
  25. Gtk2->main;
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Duda Gtk

Notapor visualfree » 2009-11-19 18:49 @826

Gracias por la pronta respuesta. Disculpa, ¿me podrías decir los alcances de HBox, por favor?

Saludos.
visualfree
Perlero nuevo
Perlero nuevo
 
Mensajes: 41
Registrado: 2009-11-19 03:01 @167

Re: Duda Gtk

Notapor explorer » 2009-11-19 18:55 @830

Por aquí ya hemos hablado del asunto. Solo hay que usar el motor de búsqueda o Google. Por ejemplo:
* Quiero aprender a crear ventanas con Gtk y Perl
* Cómo coloco un separador con Gtk y Perl
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

textBox Gtk2

Notapor visualfree » 2009-11-19 20:31 @897

Sabes que por todos lados he buscado el TextBox, msgbox, inputbox, pero no los puedo encontrar. Agradecería me dijeras cómo...
visualfree
Perlero nuevo
Perlero nuevo
 
Mensajes: 41
Registrado: 2009-11-19 03:01 @167

Re: textBox Gtk2

Notapor visualfree » 2009-11-19 21:16 @927

Acá avancé un poco, pero necesito imprimir el mensaje que escribo en un Gtk2::Entry en un Gtk2::Dialog... al presionar en el botón...

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. use strict;
  2. use warnings;
  3. use Gtk2 '-init';
  4. use constant TRUE => 1;
  5. use constant FALSE => !TRUE;
  6. sub actboton1 {
  7.  
  8.  
  9. }
  10. my $window = Gtk2::Window->new( 'toplevel' );
  11. $window->set_border_width( 10 );
  12. $window->signal_connect( destroy => sub{ Gtk2->main_quit } );
  13. my $label = Gtk2::Label->new( 'Ingrese Texto' );
  14. my $entrada=Gtk2::Entry->new;
  15. my $boton1 =Gtk2::Button->new('bont1');
  16. $boton1->signal_connect( clicked => \&actboton1);
  17. my $vbox = Gtk2::VBox->new(5, FALSE );
  18. $vbox->pack_start($label,FALSE,FALSE,FALSE);
  19. $vbox->pack_start($entrada,FALSE,FALSE,FALSE);
  20. $vbox->pack_start($boton1,FALSE,FALSE,FALSE);
  21. $window->add( $vbox );
  22. $window->show_all;
  23. Gtk2->main;
  24.  
  25.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4


Saludos...
visualfree
Perlero nuevo
Perlero nuevo
 
Mensajes: 41
Registrado: 2009-11-19 03:01 @167

Re: textBox Gtk2

Notapor visualfree » 2009-11-19 23:02 @001

Acá logré algo positivo :)

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. use Gtk2 '-init';
  2. sub actboton1 {
  3.    $texto = $entrada->get_text;
  4.    my $dialog = Gtk2::Dialog->new ('hola', $main_app_window,
  5.                                     'destroy-with-parent',
  6.                                     'gtk-ok' => 'none');
  7.     my $label = Gtk2::Label->new ($texto);
  8.     $dialog->vbox->add ($label);
  9.     $dialog->signal_connect (response => sub { $_[0]->destroy });
  10.     $dialog->show_all;
  11. }
  12. my $window = Gtk2::Window->new( 'toplevel' );
  13. $window->set_border_width( 10 );
  14. $window->signal_connect( destroy => sub{ Gtk2->main_quit } );
  15. $label = Gtk2::Label->new( 'Ingrese Texto' );
  16. $entrada=Gtk2::Entry->new;
  17. $boton1 =Gtk2::Button->new('Mostrar');
  18. $boton1->signal_connect( clicked => \&actboton1);
  19. $vbox = Gtk2::VBox->new(5, FALSE );
  20. $vbox->pack_start($label,FALSE,FALSE,FALSE);
  21. $vbox->pack_start($entrada,FALSE,FALSE,FALSE);
  22. $vbox->pack_start($boton1,FALSE,FALSE,FALSE);
  23. $window->add( $vbox );
  24. $window->show_all;
  25. Gtk2->main;
  26.  
  27.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
visualfree
Perlero nuevo
Perlero nuevo
 
Mensajes: 41
Registrado: 2009-11-19 03:01 @167

Re: Duda Gtk

Notapor explorer » 2009-11-20 04:15 @218

Recuerda que puedes reeditar tus mensajes. Así no tienes que agregar mensajes uno tras otro. Hay un botón de edición en cada mensaje.
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 42 invitados

cron