List Info

Thread: From Tk to Gtk




From Tk to Gtk
user name
2007-03-05 12:16:17
Hello every body I'm currently programming under perl Tk,
but I want to 
move to perl Gtk, I want to know the diffrences between
these two and 
wich is the last version of Gtk, thanks in advanced!!

_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: From Tk to Gtk
user name
2007-03-05 12:50:06
On 3/5/07, Judith <jaltamiranocorreolux.com.mx>
wrote:
> Hello every body I'm currently programming under perl
Tk, but I want to
> move to perl Gtk, I want to know the diffrences between
these two and
> wich is the last version of Gtk, thanks in advanced!!

You can find the latest versions of the Perl module on
gtk2-perl.sf.net.  The differences between Tk and Gtk are
too numerous
to talk about in any detail, but the biggest differences are
in the
way you pack and create widgets.  In Tk you create widgets
using a
parent widget.  in Gtk you create the widgets separately. 
In Tk you
specify how a child widget is placed on it's parent with
pack or some
other function.  In Gtk2 there are some widgets whose whole
purpose is
to be containers, and you add widgets to them.  Generally
you will use
box widgets (Gtk2::HBox and Gtk2::VBox) to control the
layout.  There
are others: Gtk2::Table is a tabular layout, Gtk2::VPaned
and
Gtk2::HPaned hold two widgets and allow you to move the
separator
between them, Gtk2::Notebook provides a tab based layout,
Gtk2::Fixed
is a fixed position layout, and others.

You can learn more at http://gtk2-per
l.sourceforge.net/doc/

Here is a quick hello world demo.

#!/usr/bin/perl

use strict;
use Gtk2;

Gtk2->init; #setup Gtk2

my $window = Gtk2::Window->new; #similar to MainWindow
my $hbox   = Gtk2::HBox->new;
my $label  = Gtk2::Label->new('Hello World');
my $button = Gtk2::Button->new('Quit');

#windows are containers that can only hold one item
#so we need another container that can hold both
#the label and the button, hbox is good for this
#since it can hold any number of items and puts them in
#a horizontal row
$window->add($hbox); #window contains the hbox
$hbox->add($label);  #hbox contains the label
$hbox->add($button); #hbox contains the label and the
button

#when we click on the close button of the window we want
#the program to exit, so hookup the window's destory signal
#with a function that will exit the program
$window->signal_connect(destroy =>
&quit_program);

#we also want to quit when the quit button is pressed
#so we attach the same function to the button's
#clicked signal
$button->signal_connect(clicked =>
&quit_program);

#nothing will show up until we tell Gtk to
#show the widgets, we can do this by calling
#the show method of every widget or by
#calling the show_all method of window
$window->show_all;

Gtk2->main; #start the main loop

sub quit_program {
        Gtk2->main_quit;
}
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: From Tk to Gtk
country flaguser name
United States
2007-03-05 13:13:52
Unfortunately, you're not talking about a conversion so much
as a
rewrite.

Widget packing is different, but it's just a bit of
rethinking.

The biggest differences I encountered is you don't bind
variables to
your widgets.  You are probably used to supplying a variable
reference
to your widgets, and having any changes automatically change
on screen.
You can't do this in Gtk2.

You are going to have to explicitly set the values in a
widget, and then
explicitly get it back out.  It's a bit more typing, and
requires you to
think about your program flow a little more finely, but it's
all to the
better.

You'll find Gtk2 much faster, prettier, and useful.  The
only problem is
the learning curve is a bit steeper.  There's lots of help
to be had
here on the list though.

Feel free to email me directly if you have specific
questions.  I have
worked up some Gtk2-perl equivalents to Perl/Tk's 'Lab'
widgets such as
LabEntry, LabComboBox, etc.  They're workable, but not
really ready for
CPAN.  

Good luck, and welcome.
-- 


-Nik

_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: From Tk to Gtk
country flaguser name
United States
2007-03-05 14:26:37
On Mon, 05 Mar 2007 12:16:17 -0600
Judith <jaltamiranocorreolux.com.mx> wrote:

>Hello every body I'm currently programming under perl
Tk, but I want to 
>move to perl Gtk, I want to know the diffrences between
these two and 
>wich is the last version of Gtk, thanks in advanced!!

< my 2 cents>
To me, the biggest difference between Tk and Gtk2 is the 
way you need to manage your callbacks and events in more
detail with Gtk2.

In Gtk2, the return value from
many callbacks determine if they will stop. 
It dosn't sound like much, but it represents a big
break in thinking from Tk's way of doing it. You will 
find all sorts of seemingly complex code in callbacks,
that sometimes return TRUE, sometimes FALSE; and
this determines the flow of the script. 

The event loop, adding and removing subs to it, is an
important feature of Gtk2, whearas Tk tends to hide
the internals of the Mainloop from you.  

One big advantage of Gtk2, is that it can be made
thread-safe, and this is a
big step forward over Tk.

Another Gtk2 advantage, is that is uses the themes setup for
your
other apps like mozilla or firefox.... so your Perl/Gtk2
programs
look like your other apps.

One big brick wall everyone runs into is the way lists are
handled in Gtk2. Tk is alot simpler, but Gtk2 does have the
the Ex and Simple series of list-releated modules to make
it
easy. 

Another advantage that Tk still has, is a better Canvas
widget. The
Gnome2::Canvas has anti-aliasing, but otherwise, it is not
as feature packed
as the Tk::Canvas. 

A very good intro to Gtk2 is

http://forgeftp.novell.com/gtk2-perl-study/download/

One other big advantage of Gtk2, is the underlying c
libraries.
There is an active, and smart group of programmers working
on
the libraries. If you look thru the c libraries at
ftp.gnome.org/pub,
you will find many specialty libraries, ranging from OpenGL
to
Window Manager control, etc. All of these libraries, could
conceivably
be made into Perl/Gtk2 versions.

And finally, there is Glib. I find this one of the best
parts of Gtk2.
It lets you setup an event loop in a command-line perl
program,
which is extremely handy in writing simple scripts that will
run
without X.

</2 cents>

So, my advice, is if you can afford the time, Gtk2 is worth
it.
It has some very nice widgets like Gtk2::ImageViewer( which
has
mouse zooming and panning), and things Tk can't do yet, like
SVG. 

If you are pressed for time, Tk is quicker, but Gtk2 gives
you a wider
universe. 

zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.
html
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: From Tk to Gtk
user name
2007-03-05 15:42:26
I'm quite surprised no one has suggested using Glade yet.
It's a very easy way to create your graphical interface.

Honnestly, gtk2-perl and Glade have been a killer combo for
me.
It allowed me to build up prototypes or applications very
quickly
without much pain (i won't mention the localization stuff
that is
still abit weird).

-Pascal
-- 
Homepage (http://organact.mine.nu)
Debian GNU/Linux (http://www.debian.org)
LACIME: École de technologie supérieure (http://lacime.etsmtl.ca)
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: From Tk to Gtk
country flaguser name
Germany
2007-03-06 10:45:41
Hi Judith,

* Judith <jaltamiranocorreolux.com.mx>
[2007-03-05 19:15]:
> Hello every body I'm currently programming under perl
Tk, but I
> want to move to perl Gtk, I want to know the diffrences
between
> these two and wich is the last version of Gtk, thanks
in
> advanced!!

the biggest difference is probably that with Gtk2, you have
a
fighting chance of writing tidy code. Tk is really effective
at
making the application source code incredibly ugly.

I know that’s not much help , but I
don’t really have much to
add to what has already been said about the technical
differences.

Gtk2 and Tk represent very different ways of doing the same
thing. Tk is easier for small stuff, but it gets nasty very
quickly. Gtk2 has more explicit indirection, so there is
more
coding overhead, sometimes a lot more; this is particularly
noticable in small programs. However it makes it easy to
divide
the code into pieces that have exactly one responsibility,
which
makes it tremendously easier to write large programs with
less
code and cleaner code than Tk allows.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/&g
t;
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list
[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )