#!/usr/bin/perl
use strict;
use warnings;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(300, 200);
my $target_ip = '127.0.0.1';
my $label1 = Gtk2::Label->new ("IP ".$target_ip);
my $vbox = Gtk2::VBox->new(FALSE, 3);
$vbox->pack_start($label1, FALSE, FALSE, 4);
my $button = Gtk2::Button->new("Ok");
$vbox->pack_end($button, FALSE, FALSE, 4);
$button->signal_connect(clicked => sub {
$target_ip = '88.88.88.88';
$label1->set_label("IP ".$target_ip); # That's what you need!!!
});
$window->add($vbox);
$window->show_all;
Gtk2->main();
Perl gtk2 window update
Вопрос
Recently when i was writing gtk2 program in perl I've runned into a little problem. I've got a main window which uses variables in labels and buttons to display user some data.
my $label1 = Gtk2::Label->new ("IP ".$target_ip);
my $label2 = Gtk2::Label->new ("Port ".$target_port);
my $label3 = Gtk2::Label->new ("Threads ".$thread_number);
And after updating $target_ip variable (by pop up window) or any other variable used in my main window for that matter by user nothing happens, so my question is how can i update window in Gtk2 i've tried re drawing it by calling window function again but for some reasons the old one still stays up even after issuing Gtk2->main_quit. Also i'm aware this may be a lame question but i'm using Gtk2 library for the first time to write a major project and I'm not really expert in it yet. Here's my code so far ($ok variable represents ok button in pop up window which updates other variables in main window)
$ok->signal_connect (clicked => sub {
$target_ip = $text_area->get_text;
Gtk2->main_quit; #Pop-up window
main_Gtk()
#Rebuild Attack window with given parameters / variables
Решение