Bin-Blog logoBin-Blog

Learn about the latest in Web Development – as soon as I do.

Tk Verses Gtk(And Python verses Tcl)

By • Oct 31st, 2007 • Category: Design, Opinion, Review, Scripts

Back when I was using Windows, I searched for some language that would let me create GUI application. I knew C++ – but creating a GUI using C++ was very, very hard. After some searching I found Tcl/Tk – it was perfect. I liked Tk so much that I used it to create GUI in perl programs. And in Ruby. And in Python. I even wrote tutorials for Tcl/Tk and Perl/Tk. Then I discovered Linux. initially I was glad that I did not choose VB – that would mean that I have to throw away all my custom programs. But since I used open languages like Tcl, Perl, Ruby etc, they will run on Linux as well.

But when I actually ran the programs in Linux, I got the shock of a lifetime. The applications I created looked bad – really bad…

TK Screenshot - Ugly

I still use many Tk programs – but because of the looks issue, I decided to stop using Tk for my new programs. So I decided to try GTK. I even created a small application using PyGTK(my first) to view the harddisk space usage in Linux – Frees.

Frees Screenshot

It was a very simple application – all I had to do is run the ‘df’ command, parse its output, and display a small table using that data. I was expecting around 100, 150 lines of code at the most. But after I created the app, I have 500+ lines of code.

At first, I thought that it was a mistake on my part – I thought that I was not using the best method. But then I came across an article in Redditgnocl or PyGtk?.

PyGtk is still the most recommended binding for Gtk. A lot of programs in Linux is written using PyGtk. So naturally there are a few advantages for using it…

  • It will be the more ‘road-tested’ binding.
  • Many system will have it installed by default.
  • Bigger community – so…
    • more support
    • more examples
    • more tutorials
    • etc.

One the other hand, I have to write more code.

Conclusion

If it is a private script – only useful for myself, then I will use Tcl/Tk or Gnometcl. If the script could be distributed, like Frees, then I will use Python GTK.

What about the other options…

  • wxWidgets
  • PyQT
  • Ruby/GTK
  • Perl/GTK

Any recommendations for me on which library to use? Please leave it in the comments.


8 Responses »

  1. […] > Du hysterisch wirst. Denn die Systemschnittstellen von Linux > > und Darwin sind recht aehnlich. Es stellt kein prinzipielles > > Problem dar, Mac OS X-Binaries in einer Linux-Umgebung > > ablaufen […]

  2. […] want to insert a disclaimer here – I am not that good with python. We never really clicked. I have done very limited work in Python. So if you notice any problems with the below script, let […]

  3. […] Tcl, or Tool Command Language, will not be found in the ‘most popular languages’ hall of fame. That is partly because of its ‘wierd’ syntax. But those who know Tcl will tell you that Tcl is a pleasure to work with. I have a special interest in Tcl – its the language that introduced me to GUI programming(Tcl/Tk). Now, when ever I see a GUI toolkit, I compare it to Tcl. […]

  4. […] GUI applications. I continue that even today – as Tcl/Tk is well supported in Linux(even though Tk apps looks very bad in linux). All the Tcl apps I created are available on the Tcl/Tk […]

  5. nitisha says:

    how do we do runtime allocation of arrays?
    or while parsing a file if i come across “[Default]” i need to use whatever is in the square bracket as my arry name and the cintents below it should be stored as the values in the array?

  6. Pete says:

    Tk is a bit outmoded. Themed Tk (Ttk aka Tile) provides the modern look and feel you’re looking for.

  7. Chris says:

    I wonder if your count of 500+ lines of code is including all the code to “create” the GUI. If so I’d like to see your code because there is no way that should take 500 lines of code. Also with the more recent ability of GTK to load XML files with UI definitions you don’t have to worry about all the hard coded GUI instantiation code.

    I’ve tried both Tk and GTK in Python and my biggest beef so far is that I’ve learned that even recent version of GTK do not use native dialogs for things like opening files on Windows, where as Tk seem to be getting better and better at matching the OS it is running on. The GTK file open dialog is horrible. Also I think that Tk is getting better in general at having the widgets look like the standard widgets of the OS that you are running on (Windows, Mac, etc…).

  8. Anonymoys says:

    Tcl is only ugly if you use the *old* Tk.

    If you use the new themed widgets under the namespace ttk:: they’ll look beautiful.

    Old Tk:
    package require Tk
    button .b -text “Click me” -command exit
    pack .b

    New Tk:
    package require Tk 8.5
    ttk::button .b -text “Click me” -command exit
    pack .b

    And yes, Tcl/Tk is the easiest way to create GUIs. The code above in other toolkits would be like 10 lines or more and you’d probably need an IDE with GUI builder instead of just a text editor.

    Check out the wiki: http://wiki.tcl.tk
    The community is helpful.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>