Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Undesired space between Tk Canvases

by liverpole (Monsignor)
on Apr 25, 2007 at 00:10 UTC ( [id://611882]=perlquestion: print w/replies, xml ) Need Help??

liverpole has asked for the wisdom of the Perl Monks concerning the following question:

I'm sure I'm missing something obvious here.

Within my Perl/Tk application, I'd like to have a 256x256 white Canvas in the center of 4 other Canvas objects (of different colors here, while debugging).

I've tried every option I can think of, searched for a possible solution, and perused the most recent volume of "Mastering Perl/Tk" -- all to no avail.

Here is a stripped down version of my original program which still shows the problem.  When you run it, you get a white Canvas in the middle of 4 Canvas "strips" of other colors.  I'd like the Canvas objects to all be flush with one another, but there's a little space between each of them.

I know this has to be something simple and easy, but I'm just not seeing it.  It's not the enclosing Frame (at least I don't think it is), because the Frame has a blue background, and there isn't any blue showing through anywhere.

Can someone point me to a solution?  Thanks!

#!/usr/bin/perl -w # Strict use strict; use warnings; # Libraries use Tk; # Main program create_gui(); # Subroutines sub create_gui { my $mw = new MainWindow(-title => 'Type "Escape" to exit...'); $mw->bind('<Escape>' => sub { $mw->destroy() }); my $frame = $mw->Frame(-background => 'blue'); $frame->pack(-expand => 0, -fill => 'both'); # Note: 288 = 256 + 16 + 16 canvas($frame, 'hotpink', 'left', 16, 256 + 16 + 16); canvas($frame, 'gold', 'right', 16, 256 + 16 + 16); canvas($frame, 'maroon', 'top', 256, 16); canvas($frame, 'white', 'top', 256, 256); canvas($frame, 'purple', 'bottom', 256, 16); MainLoop; } sub canvas { my ($w, $background, $side, $width, $height) = @_; my $canvas = $w->Canvas(-background => $background); $canvas->configure(-width => $width); $canvas->configure(-height => $height); $canvas->pack(-expand => 1, -fill => 'both', -side => $side); return $canvas; } # # Key: H = Hotpink, M = Maroon, P = Purple, G = Gold, . = White # # The GUI I'm actually getting: The GUI I'd *LIKE* to get: # # +------------------------------+ +------------------------------+ # |Tk Type "Escape" to exit..." | |Tk Type "Escape" to exit..." | # +------------------------------+ +------------------------------+ # |H MMMMMMMMMMMMMMMMMMMMMMMM G| |HMMMMMMMMMMMMMMMMMMMMMMMMMMMMG| # |H G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H ........................ G| |H............................G| # |H G| |H............................G| # |H PPPPPPPPPPPPPPPPPPPPPPPP G| |HPPPPPPPPPPPPPPPPPPPPPPPPPPPPG| # +------------------------------+ +------------------------------+ #

Update:  After Super-Searching some more, I came across this node, by the venerable zentara.  He used a Canvas option I hadn't tried:  -highlightthickness => 0.

Although I'm still not exactly sure what highlightthickness is used for, it does the trick; inserting the following line completely addresses my problem:

$canvas->configure(-highlightthickness => 0);

Thanks, zentara -- you help me even when you're not logged in!


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re: Undesired space between Tk Canvases
by shmem (Chancellor) on Apr 25, 2007 at 04:44 UTC
    Press <Tab> in that Tk window. See? You want
    $canvas->configure(-highlightthickness =>0);

    :-)

    update: I see you found out while I was writing the answer... highlightthickness is the width of the highlight border (default 1 pixel). If you set it to 0, the element will not highlight while cycling through the elements with <Tab>, since there is nothing to colour. If you want to leave the border there, use

    $canvas->configure(-highlightbackground => $background);

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      ++shmem, and thanks,

      Your example illustrates the meaning of highlightthickness quite nicely.  Typing <Tab> several times makes it very clear why you might want to have a space there (I don't of course, because I'm only using the border Canvases to frame the inner one, and thus don't need to select them).

      Similarly, just as I had never used highlightthickness before, highlightbackground was also new to me.  So that's 2 new things you've taught me in Tk -- thank you!


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found