Skip to content

Commit 5ee5d11

Browse files
committed
Added Spinbox program
1 parent 21adcf3 commit 5ee5d11

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

8-Spinbox.pl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#! /usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use diagnostics;
6+
use feature ':5.14';
7+
use Gtk3 '-init';
8+
use Glib qw/TRUE FALSE/;
9+
10+
my $window = Gtk3::Window->new('toplevel');
11+
$window->set_title("Spinbox Example");
12+
$window->set_position("mouse");
13+
$window->set_default_size(200, 50);
14+
$window->set_border_width(5);
15+
$window->signal_connect (delete_event => sub { Gtk3->main_quit });
16+
17+
my $vbox = Gtk3::Box->new("vertical", 5);
18+
$window->add($vbox);
19+
20+
my $adjust = Gtk3::Adjustment->new(5, 0, 10, 1, 10, 0);
21+
my $spin = Gtk3::SpinButton->new($adjust, 1, 1);
22+
$vbox->pack_start($spin, FALSE, FALSE, 0);
23+
24+
my $hbox = Gtk3::Box->new("horizontal", 5);
25+
$vbox->pack_start($hbox, FALSE, FALSE, 0);
26+
27+
my $zero_button = Gtk3::Button->new('Zero');
28+
$hbox->pack_start($zero_button, FALSE, FALSE, 0);
29+
$zero_button->signal_connect (clicked => \&zero, "zero");
30+
31+
my $check_accuracy = Gtk3::CheckButton->new_with_label('High accuracy');
32+
$hbox->pack_start($check_accuracy, FALSE, FALSE, 0);
33+
$check_accuracy->signal_connect (toggled => \&toggle_accuracy, "accuracy");
34+
35+
$window->show_all;
36+
Gtk3->main;
37+
38+
sub zero {
39+
my ($widget, $data) = @_;
40+
$spin->set_value(0);
41+
}
42+
43+
sub toggle_accuracy{
44+
my ($widget, $data) = @_;
45+
my $value = $widget->get_active;
46+
if ( $value == TRUE ) {
47+
$spin->set_digits(2);
48+
} else {
49+
$spin->set_digits(1);
50+
}
51+
}

0 commit comments

Comments
 (0)