GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hello World in Tcl/Gnocl

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
wjgiddings
GTK+ Geek


Joined: 06 Feb 2009
Posts: 71
Location: The Midlands, England

PostPosted: Tue Apr 21, 2009 7:51 pm    Post subject: Hello World in Tcl/Gnocl Reply with quote

Whilst Tcl (pronounced 'Tickle') is no longer the 'coolest' scripting language out there, it is perhaps the most stable and mature of all dynamic languages.

In a recent survey, it became apparent that most Tcler's are veteran users with relatively few newcomers registering a vote. Why is that?

Perhaps the abscence of new books in the shops on Tcl as compared to say Python, Perl and Ruby are not so much an indication of the Tcl being 'forgotten' but simply due to the fact that the online resources for the package are second to none and that the language is so incredibily easy to use. But, as everyone likes a good book, perhaps its easy to assume that having lots of books on the market on other languages implies that these as the best of possible choices. Is that always the case? Perhaps the demand for such books is due to the difficulty and not ease in learning and using those languages.

What is most popular is not necessarily the best choice available. Programming languages are just as subject to the foibles of fashionability as any other commodity.

So, in order to generate some interest from fellow Gtk developers reluctantly re-inventing the wheel, or trying to create a Pythonese version of a C-sample, I ask you: why not try Gnocl to develop those Gtk GUIs? Save all your the hard C-coding for optomising speed critical routines and building them into commands which can be made available to a Tcl interpreter. Spend more of your valuable time developing applications rather than support libraries!

So, to whet your appetite here's the Tcl/Gnocl version of the most ubiquitous of all programs: 'Hello World'. Oh, by the way, all the Gtk window, container and button properties, styles, signals and sometimes a few other useful goodies too are all there in the package waiting to be used. There's no extra coding, no glue or C-library wraps. Its all been done. Why should programming be a burden? How much simpler can it get?

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 # helloWorld.tcl
 #!/bin/sh
 # the next line restarts using tclsh \
 exec tclsh "$0" "$@"

 # load the Gnocl package
 package require Gnocl

 # create a button, print 'Hello World' to console when clicked.
 set but1 [gnocl::button -text "Click Me!" -onClicked {puts "Hello World"}]

 # create a container to hold the widget, not necessary but we want to keep the button small
 set box [gnocl::box]

 # add the button to the container, using -fill {0 0} will restrict the size,
 # but allow its position to be adjusted when the window is resized
 $box add $but1 -fill {0 0} -expand 1

 # create the window, the parameters speak for themselves
 gnocl::window -title "helloWorld.tcl" -onDelete {exit} -child $box -widthRequest 200 -heightRequest 50

 # not necessary, but programmatically correct
 gnocl::mainLoop


Gnocl is available from SourceForge http://sourceforge.net/projects/gnocl and the lasters version Tcl/Tk can be installed from your Linux distro sources.

Happy hacking

Will


Last edited by wjgiddings on Fri Apr 24, 2009 7:37 am; edited 1 time in total
Back to top
caracal
GTK+ Guru


Joined: 21 Jun 2007
Posts: 207
Location: Wilkes Barre Pa

PostPosted: Wed Apr 22, 2009 4:38 pm    Post subject: Reply with quote

You might want to think about getting gnocl added to http://www.gtk.org/language-bindings.html
Back to top
wjgiddings
GTK+ Geek


Joined: 06 Feb 2009
Posts: 71
Location: The Midlands, England

PostPosted: Wed Apr 22, 2009 5:03 pm    Post subject: Listing Gnocl Reply with quote

Y'know, when I first started Gnocl coding it was. For some reason its not on the list anyomore.

Will
Back to top
caracal
GTK+ Guru


Joined: 21 Jun 2007
Posts: 207
Location: Wilkes Barre Pa

PostPosted: Wed Apr 22, 2009 5:22 pm    Post subject: Reply with quote

They got a new site maintainer recently and there is a lot of content that use to be there that isn't anymore. That could be the reason.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP