Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Make decoration-less windows in TK, and not lose functionality.

by wombat (Curate)
on Aug 24, 2003 at 16:39 UTC ( #286213=sourcecode: print w/ replies, xml ) Need Help??

Category: GUI Programming
Author/Contact Info Wombat; the man, the legend, the chosen one.
Description: Some discussion went on recently about how to make decorationless windows in TK. The answer of course is to use the popular $mw->overrideredirect(1); function. However this was determined unsatisfactory because it prevented the window from being moved about the screen.

Well, I solved that.

All it is is that you make a border of widgets around the screen of whatever you want, and use the geometry function on the main window to move it about. Use the pointerxy construct to find out where the cursor is. Have fun!
#!/usr/bin/perl -w
use Tk;
use strict;

my @Custom_Border = ();
my @frames = ();
my ($x, $y) = 0;
my $flag = 0;

my $mw = MainWindow->new(-background=>'#000000',
             -title=>"You Should Never See This.");

$mw->overrideredirect(1);

$frames[0] = $mw->Frame()->pack(-fill=>'both');
$frames[1] = $mw->Frame()->pack(-fill=>'both');
$frames[2] = $mw->Frame()->pack(-fill=>'both');



$Custom_Border[0] = $frames[0]->Label(-background=>'#FFFFFF',
                      -borderwidth=>0,
                      -text=>"Top")->pack(-side=>'top',
                                  -fill=>'both');
$Custom_Border[1] = $frames[1]->Label(-background=>'#FFFFFF',
                      -borderwidth=>0,
                      -text=>"Left")->pack(-side=>'left',
                                  -anchor=>'w',
                                  -fill=>'both');

$frames[3] = $frames[1]->Frame()->pack(-side=>'left',-fill=>'both');

$Custom_Border[2] = $frames[1]->Label(-background=>'#FFFFFF',
                      -borderwidth=>0,
                      -text=>"Right")->pack(-side=>'right',
                                  -anchor=>'e',
                                  -fill=>'both');
$Custom_Border[3] = $frames[2]->Label(-background=>'#FFFFFF',
                      -borderwidth=>0,
                      -text=>"Bottom")->pack(-side=>'bottom',
                                  -fill=>'both');
 
my $Q_Button = $frames[3]->Button(-text=>"Quit",-command=>sub {$mw->de
+stroy();})->pack();




$Custom_Border[0]->bind('<Button-1>',sub {$flag = 1;});
$Custom_Border[0]->bind('<ButtonRelease-1>',sub {$flag = 0;});

$Custom_Border[0]->bind('<Motion>',sub {
        if ($flag) {
          ($x,$y) = $Custom_Border[0]->pointerxy;
          $mw->geometry("+".($x-5)."+".($y-5)); 
          printf "Moving to %d,%d\n",$Custom_Border[0]->pointerxy;
          $mw->update;
        }
});

MainLoop();

Comment on Make decoration-less windows in TK, and not lose functionality.
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://286213]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-07-12 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (239 votes), past polls