Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/Tk package 2

Status
Not open for further replies.

subtelo

Programmer
Jan 9, 2005
25
US
Want to use Perl/Tk for graphical tool in perl script. But it is not installed in my current RedHat Enterprise 5. Does anybody can give me a hint which package contain it and where I can download it. Thanks.
 
If you have yum, you can get it through that.

Code:
yum install perl-Tk

There's a slight downside though: the Tk packages for RHEL was compiled with XFT - this means that fonts in your GUI are antialiased and look nice, but I've found this makes Tk unstable and will cause segmentation faults in an unpredictable but consistent way. Any widget that uses a -font option will potentially segfault your app, and when one does, it will repeatedly be that widget that segfaults it, and no other widget; deleting and retyping the code for the widget doesn't help, if you delete it altogether then a different widget might start causing the segfaults.

You can try this package but if you run into the aforementioned segfaults, you'll need to do one of 2 things:

A) install the package yourself. Get it from CPAN ( and do the "perl Makefile.PL; make; make install" on it. You'll require the package libX11-devel to build it.

The downside here is that your package manager won't know you've installed it, and if you later decide to remove it, it won't be too easy to do.

B) download the source RPM of perl-Tk, by doing `yum install yum-utils` and then run `yumdownloader --source perl-Tk`. Extract the source RPM and change the spec so that it doesn't compile with the XFT option, and rebuild the RPM. This way you'll have an RPM that can be installed and uninstalled via the package manager, which doesn't have the unstable XFT option compiled in.

It'd be helpful to have some experience building RPMs for this option though, as you'll probably have to set up an rpmbuild directory and stuff first.

I have an RPM of perl-Tk minus XFT, but it's for Fedora 10 which has a different version of Perl than RHEL5 does, so it won't be of much help here.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Thanks all for your valuable inputs. Kirsle, sounds like it is a little bit tough for install Tk and run correctly in RH. Before I dip in it, is there any other choices except Tk to run graphics in perl? Thanks.
 
Yeah,

There's Gtk2-Perl which uses GTK+ so it'll fit in pretty nicely on a GNOME desktop environment, looking like all the other apps ya run on RHEL:
And wxPerl, which uses the wxWidgets cross-platform GUI toolkit. wxPerl will create a GUI that looks native on every platform (will fit right in with Windows apps on Windows, Mac OS X apps on Mac, and uses GTK+ on Linux):
Both toolkits are cross-platform, but Gtk2 will look like a GTK+ app no matter where it's run. In perspective though, Pidgin ( is a GTK+ app and I think it looks pretty nice on Windows; it may not fit in as perfectly as a native Win32 app but it looks good anyway.

With Gtk2 and wxPerl, there isn't very much Perl-specific documentation; you'll have to look into the C/C++ documentation for help on how to use the various widgets in them. Tk is still the best for documentation in that regard.

There are some full-featured Perl apps that use Gtk2, such as dvd::rip, so I'm pretty sure you can do a lot with Gtk2. I haven't personally had much experience with it (or wxPerl for that matter).

On wxPerl, there's a text widget that renders HTML code; however, in my experience, this only worked well on Windows. On Linux, the demo that comes with wxPerl failed horribly to render the HTML.

Personally I like Tk the best -- if you build it without XFT, it's a lot more stable on Linux. As for looks, though, it looks a lot better on Windows than it does on non-Windows; on *nix and Mac OS X, it looks like a really old-school Motif application. Example screenshots from an app I made with it:
Tk is flexible, though; you can apply a lot of styles to the widgets to make it easier on the eyes in Linux. It will never "fit in" with any other Linux apps, but you can at least make it look different on purpose. ;-) On Windows, it almost fits in with Windows apps, with some very small differences (no dotted borders inside active buttons on your dialogs, for instance).

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
I decide to dip into Tk since some of my old browsers had been built by Tk. Kirsle, welcome any input of built Tk without XFT. If there is a step-by-step tutorial, including rebuilt RMP, it is great. Thanks a lot.
 
For building an RPM...

There's a tool to create an rpm build root but I can't seem to find it right now. Basically you'll create a folder like "rpmbuild" in your home directory (ex /home/kirsle/rpmbuild), and then make a .rpmmacros file in your home directory so rpmbuild knows where your rpmbuild directory is...

Code:
cd $HOME
mkdir rpmbuild
mkdir rpmbuild/BUILD
mkdir rpmbuild/BUILDROOT
mkdir rpmbuild/RPMS
mkdir rpmbuild/SOURCES
mkdir rpmbuild/SPECS
mkdir rpmbuild/SRPMS
echo "%_topdir $HOME/rpmbuild" > .rpmmacros

Then use yumdownloader to get the source RPM. It comes with the yum-utils package if you don't already have it. You'll also need the `rpm-build` package.

Code:
yumdownloader --source perl-Tk

This will get the source RPM; on my system (Fedora 11) its name was perl-Tk-804.028-9.fc11.src.rpm.

You can open this with the archive manager that comes with GNOME; just right-click and do "Open with Archive Manager". Inside are a bunch of files, including perl-Tk.spec, a tar.gz such as "Tk-804.028.tar.gz", and maybe a few .patch files.

The patch files are custom patches that Red Hat added on to Perl/Tk. In my experience, a vanilla non-patched Tk works just fine, so we don't need those.

perl-Tk.spec can be extracted into your rpmbuild/SPECS folder, and put the Tk-804.028.tar.gz or similar into the rpmbuild/SOURCES folder.

Edit perl-Tk.spec in a text editor such as gedit, and remove or comment out any "Patch" lines (Patch0, Patch1, etc) since we aren't using them. Then scroll down to the line that begins with "%build", and there's a line there that looks like this:

Code:
%{__perl} Makefile.PL INSTALLDIRS=vendor X11LIB=%{_libdir} XFT=1

The "XFT=1" option is what builds Tk with XFT; remove the "XFT=1" option from this line.

Also under the "%prep" section there may be several lines that begin with "%patch"; delete or comment these out too.

Now you can build the new RPM. In a terminal, go to your rpmbuild directory and run the command `rpmbuild -ba SPECS/perl-Tk.spec`:

Code:
cd rpmbuild
rpmbuild -ba SPECS/perl-Tk.spec

With any luck, after a few minutes of compiling you'll end up with some RPMs. If you watch the output of the terminal it will write some lines that begin with "Wrote:" giving the path to where the RPMs were written to. Most likely it will be in a place such as "/home/kirsle/rpmbuild/RPMS/i386/perl-Tk-804.028.rpm". Just navigate your rpmbuild/RPMS directory in your file browser and you'll find them.

If there's any errors, they'd most likely involve missing dependencies that the package needs. In the spec file I have, it lists the following dependencies, so make sure you have these installed:

Code:
# Versions before this have Unicode issues
BuildRequires:  perl-devel >= 3:5.8.3
BuildRequires:  libjpeg-devel
BuildRequires:  libpng-devel
BuildRequires:  libX11-devel
BuildRequires:  libXft-devel

If you end up with an RPM, you can then simply double-click this RPM to install it. Or, on the command line as root,

Code:
rpm -Uvh perl-Tk-804.028.i386.rpm

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Actually, some of those patch files might be helpful after all. The RPM I just built on Fedora 11 with no patches had an issue with my app using Tk::Scrolled('ROText'), for some dumb error that didn't make any sense. I rebuilt it with the same patches and it works better now.

You can keep all the patch lines in there, just make sure all those ".patch" files are put into the SOURCES folder along with the tar.gz. Then the only thing to edit in the spec is the XFT=1 option.

Also note that if you've installed perl-Tk via yum before, you'll need to `yum erase perl-Tk` before installing your custom RPM.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
If somebody install it before using cpan, but not successful, since I locate Tk.pm, There is following output
/root/.cpan/build/Tk-804.028-ByfZCY/Tk.pm
/root/.cpan/build/Tk-804.028-ByfZCY/blib/lib/Tk.pm

Should I uninstall it? Thanks.
 
Hi, once I do
yumdownloader --source perl-Tk

The terminal tell me that

Loaded plugins: rhnplugin
No Match for argument perl-Tk
Nothing to download


What is the problem? Thanks.
 
Tk is hard to install via the cpan command (otherwise, cpan2rpm would be a great way to get an RPM for it pretty quickly). I don't think it's doing any harm sitting in the CPAN build directory though; you can delete it if you need to clear up hard drive space.

As for the yumdownloader thing, it might be that it's not in any of your yum repositories. IIRC it would be in the updates repository. I've never used Red Hat Enterprise Linux, only CentOS, which is the same minus the redhat trademarks and a change of yum repositories. In this case perl-Tk is in `centos-updates`.

Try a `yum search perl-Tk` and see if you get any results for that.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Do you think the problem is the RH, I got the error message once I try `yum search perl-Tk`.

Loaded plugins: rhnplugin
There was an error communicating with RHN.
RHN channel support will be disabled.
Error communicating with server. The message was:
Service Temporarily Unavailable
Warning: No matches found for: perl-Tk
No Matches found
 
Yeah, judging by that error message Red Hat probably has some downed servers.

You can try installing Tk manually. Download/extract the tar.gz from CPAN and go to its directory in a terminal and run `perl Makefile.PL`, `make`, and `make install` (the last one will require root).

If you absolutely need to erase it in the future, just locate where Tk.pm installed to and delete it and its accompanying Tk/ file. There'd also be an auto/Tk folder somewhere else to delete too.

Compiling Tk will still require libX11-devel and likely the other dependencies that the RPM needed, so if you don't have them you'll have to figure out what's wrong with yum. The plus side is that you get tech support from Red Hat, right? Just bug them about the yum issue. :p

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
I'd give extra stars for those posts if I could, Kirsle. Good work!

Annihilannic.
 
Kirsle, good idea to bug RH about the yum issue. I will post here if I got any update. Here is another star. You really are a great help.
 
I think you can only give one user one star per thread. It's the thought that counts though. ;-) Thanks.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Hi Kirsle, after I bug to Dell, I got the perl-Tk source code from Finally I rpmbuild the .rpm without "XFT=1" after I add some dependency, libjpeg-devel, libpng-devel, and tk-devel. I got two rpm files, perl-Tk-804.028-2.rf.x86_64.rpm and perl-Tk-debuginfo-804.028-2.rf.x86_64.rpm.

Then I install it by command line.
rpm -Uvh perl-Tk-804.028-2.rf.x86_64.rpm
rpm -Uvh perl-Tk-debuginfo-804.028-2.rf.x86_64.rpm

Looks like everything is fine based on the output during installation.

After I "locate Tk.pm", the output is
/usr/lib/perl5/5.8.8/Pod/Perldoc/ToTk.pm

Is it looks OK? How can I run Tk in perl script. Thanks.
 
You can run a "hello world" script.

Code:
use Tk;

my $mw = MainWindow->new(-title => "My Application");

my $label = $mw->Label (
   -text => "Hello world!",
)->pack;

MainLoop;

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top