Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Just another Perl shrine
 
PerlMonks  

TclTk interface with Perl code, is it possible?

by exilepanda (Monk)
on Jan 13, 2012 at 08:17 UTC ( #947705=perlquestion: print w/ replies, xml ) Need Help??
exilepanda has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Here's my story. I want to create a Win32 GUI application, and I started with Perl/Tk, after a while, I found that is really complex to write an interface by purely code, so I look for some GUI builder. Then, I found Tcl/Tk, seems that's the easiest and complete builder I can find.

I tried some search, but don't have a clue at a point is that : Can I build the interface with Tcl, and then finished the code with Perl?

If yes, that still one more question is that who's the host and whose the guest? I mean after the program finish, the script is interpreted by Perl or Tcl ? Coz I need to compile the app to an exe file before I distribute to my colleagues.

But if no, could you suggest any approach for me? I need a GUI builder to build the interface, and write the code with Perl... and I am on WinXP.

Moreover, I would also consider dynamic interface modifies on the fly, eg. Extends tables' rows, real time gen menu items, auto scroll bars etc. I wonder if some module can capture the Tcl interface source as objects, and then Perl can access to its properties or even extends the Tcl windows.

Please help brief me some basic idea/concept or point me to any useful documents. Thank you very very much.

Ps. I know nothing about Tcl language though. UPDATE: I use PerlApp to pack the script.

Comment on TclTk interface with Perl code, is it possible?
Re: TclTk interface with Perl code, is it possible?
by Anonymous Monk on Jan 13, 2012 at 10:04 UTC
      OMG!! This is a deep structure.... Really need time to run through... ( Orz ) But truly thanks for a very nice beginner guide. This really helps to head me to some direction with some clue. Seems I'll take a try on pTk and wxGlade way first. Thank you very much! =)
Re: TclTk interface with Perl code, is it possible?
by Anonymous Monk on Jan 13, 2012 at 14:16 UTC

    You probably can use the GUI builder you found if you take the TCL code it produces, and translate it to Perl by hand. It should not be too hard if you can find the equivalents.

    (please note I have never written a single Tk GUI in my life, so I don't know how hard this might be)

    Otherwise, you could try a different toolkit. Check whether the perl bindings for Gtk2 or Qt are easy to install (for Windows), and find a GUI builder for them. I can at least vouch that Gtk2's bindings look very similar to the C code the GUI builders often generate.

      Related to this idea, make sure to check out the TkDocs site, which can be your Rosetta Stone for figuring out Tk code. The documentation there uses Perl, Python, Ruby, and TCL.

        Wow! Thanks Man! This is a handy and lovely dictionary. Love it! Straight forward examples, will need to keep it for ever reference.
      I've downloaded and took a look into GTK2.. but seems there's no GUI builder around.. did I miss something ?

        Well, these are for linux/unix, but they may exist for windows, too:

        $ debtags search 'devel::ui-builder && uitoolkit::gtk' gazpacho - GTK+ User Interface Designer glade - GTK+ 2 User Interface Builder glade-gnome - GTK+ 2 User Interface Builder (with GNOME 2 support) gtk2.0-examples - Examples files for the GTK+ 2.0 libgai-dev - Easy to use interface to create applets & dockapps libgai0 - Easy to use interface to create applets & dockapps libglade2-ruby1.8 - Libglade 2 bindings for the Ruby language monodevelop - Development Environment for GNOME pida - Python Integrated Development Application, a Python IDE thewidgetfactory - a showcase for GTK+ widgets vdk-doc - The Visual Development Kit C++ library vdk2-tutorial - Tutorial for the Visual Development Kit C++ library 2

        Oh, and I forgot to mention WxWidgets (WxPerl) in the list of alternative toolkits. Many people seem to like that one.

Re: TclTk interface with Perl code, is it possible?
by Marshall (Prior) on Jan 13, 2012 at 16:02 UTC
    Wow! Your post covers a lot of ground!

    As far as making a .exe for Windows, I would give a "thumbs up" to the Active State PerlApp program. Over the last decade plus, these folks have improved this thing so that it works pretty well now and I am user. The most basic Active State devkit will set you back a couple of hundred bucks, but in a professional environment this will save a lot of hassle and aggravation!

    You don't say what you are using now for building .exe's. One of the issues with a Tk based .exe is getting all of the necessary stuff into the .exe. When you run from your environment just "use Tk;" may be all you need because many widgets that are used are found dynamically during run-time. When I write Tk code destined for a .exe, I reflexively just put in a "use Tk::Label;" or whatever whenever I use a new widget in the code. That is one way to "force" the Label widget into the .exe.

    However, Active State has developed a number of heuristics that scan the source code and automatically include the necessary widgets! This is very helpful! The alternative is to run the .exe, exercise all possible widgets to make sure that they are there and do something to get the "missing ones" when a run-time bomb happens - adding a "use" statement in the source code is, I believe better than adding command line compile options. However, it is even more robust to have Active State figure this out at "exe build time". In the old days, I'd miss one and have to repeat the build, test, modify cycle many times.

    Anyway having the "smart" PerlApp that knows about Tk methods saves a lot of hassle and prevents errors of omission that are only apparent at run-time.

    One advantage of using an older toolkit, like Tk is that there are a lot of books and examples available. I liked "Mastering Perl/Tk" by Steve Lidie and Nancy Walsh. This will show you how to write a lot "smarter", easier to understand and ultimately less code for the same job. Build "widget factories" for similar things.

    My experience with writing GUI's is that the amount of time that I spend planning the GUI is far, far more than the actual coding of the basic layout. I spend a lot of time with "pencil and paper". The #1 tip: draw a picture of what you want on a scratch pad and use more frames to get the geometry to work out! The most used geometry (simple pack, instead of grid or others) has served me well although GUI development is not my primary coding focus.

    The aggravating parts that consume most of the time are dealing with various screen resolutions and things like mouse focus and binding issues. I'm not sure how much a GUI builder would help with that?, if at all.

      Yes, I found that PerlApp is a nice stuff for pack up the script. I just quite unsure how to build the GUI in a fast way with Perl codes.

      I do experience how to write Perl/Tk codes, but just too time consuming. This will not be the end product, the task force will just take this for *prototype running and loads of change is coming ahead for sure.

      * The prototype application could at lease show some interaction when click on here, or mouseover there..

        Again, my GUI I/F's takes 2-3 weeks or more typically a month to plan out how they work. A few days or even a week to code the plan is not that significant. The 2 weeks to a month deciding how it will work is the most "design effort" and that part is hard. You just will not come up with a good GUI, if you "slap things together" - the planning part is the most part. The implementation part is the least part.
        I would go with the Active State Komodo full blown IDE. This will cost some bucks (many bucks), but you will get something for those bucks. These people will talk to you on the phone and get you going. Doing it "cheap" doesn't seem to be the main parameter here - "hey, boss I need a $700 program to do my job" - Bingo! I would "punch that ticket" just to get on with the show.
Re: TclTk interface with Perl code, is it possible?
by sam_bakki (Monk) on Jan 16, 2012 at 13:46 UTC

    Hi exilepanda

    I was looking for good GUI interface for perl and I was also looking with same requirement as you. I need a good GUI editor and i will only write code for events not for GUI elements.

    Basically i was looking similar to Visualbasic in Visual studio.

    Tk was fine but it was old and Tkx do not have very good editor etc etc etc research and perl Gtk2 very well suited for me.

    You can use Glade GUI editor tool and create a GUI in IDE, store it as XML file and load from your perl program. According to me this is as easy as VB

    one major issue with perl GTK2 is there is very less documentation about it , So i always used python Gtk2 doc to know about the API and code in perl

    I have also started a perl GTK2 based open source project just to show the power and easiness of perl GTK2 & glade GUI editor

    You can take a look at the code and get information about perl GTK2 based development.

    Read development environment setup here:  http://code.google.com/p/saaral-soft-search-spider/

    Downloadcode here:  http://code.google.com/p/saaral-soft-search-spider/downloads/detail?name=search-spider-1.2.zip

    Note: Gtk2 runtime , Glade IDE is available in binary form for windows also. I use it in Windows 7 without issues. Perl Gtk2 and other related modules available for ActivePerl 5.12 via http://www. sisyphusion.tk/ppm/ repository.

    Installing these modules is like piece of cake eating. Big thanks to Syphilis (perl Monk) to make these modules available to perl world

    Final Note: I tried Active State perl app to bundle perl Gtk2 application which works like charm. No problems

      Wow! A very nice and easy walk through! I will try it again, coz I didn't have much success before.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://947705]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-04-17 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (453 votes), past polls