Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

tk question: strick app cann't close by clicking

by benlaw (Scribe)
on Apr 24, 2002 at 13:20 UTC ( [id://161676]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

hi monks,

well in the mastering ptk p. 240 it has a resizable which can strict app resize event,

however, i can't find a method which can disable the "X" (close) button in the top right corner, so i can strict user must close by click a 'exit' button i create~

(if the book has mentioned about, i'm sorry for my careless~ :P , and thx to point out)

  • Comment on tk question: strick app cann't close by clicking

Replies are listed 'Best First'.
(ichi) Re: tk question: strick app cann't close by clicking
by ichimunki (Priest) on Apr 24, 2002 at 14:31 UTC
    You can't find it because it probably does not exist. :)

    The "decorations" in title bars are typically the responsibility of the window manager (which you may or may not have much control over-- especially with Tk). Reading the perldoc for Tk::Wm we find a $toplevel->wrapper() method which will give some info about the window holding this Toplevel widget. We also find that there is a Tk::Mwm module for manipulating the Motif window manager, which does have methods for controlling decorations, but may or may not suffice when running other wms, like KDE or Sawfish or Windows (some of these may have their own modules).

    What you can do to avoid the user sidestepping your dialog box by clicking the close button is arrange a variable to be set by the button you want the user to use. If that variable is not set correctly when the dialog closes, simply re-open the dialog (with an optional stern warning to use the button this time). This will prevent those of us using window managers that support various destroy methods from getting around the lack of a close button as well.
      thx for ichimunki
      oh :( doesn't exist , feel sad ar~
      because my program only have 1 page , I should use MainWindow instead of Dialog box
      thx...~
Re: tk question: strick app cann't close by clicking
by BlueBlazerRegular (Friar) on Apr 24, 2002 at 16:33 UTC

    Check page 243 of "Mastering Perl/Tk", specifically the 'Window Properties' section.

    Assigning a empty sub to the WM_DELETE_WINDOW callback turns the button off - like so:

    $mw->protocol( WM_DELETE_WINDOW, sub{} );

    You'll need to turn off strict subs, as it doesn't like the bareword WM_DELETE_WINDOW. Although I'm sure there is a way of getting around that - I just don't know it...

      REALLY Thx BlueBlazerRegular !! ^O^
      I can fully control the window widget ~!
      Really i don't understand what 'protocol' is talking about when i read it before~Thx :D
      Great trick. What it really does is capture the signal sent by clicking the close button and smother it. This prevents the button from working, but doesn't necessarily make it go away (it doesn't on the Windows machine I am using just now)-- which as a user-interface thing is bad. The user who tries to click the close button may actually become frustrated and close the window some other way. Or they may just think the programmer is incompetent. ;)

      By the way, you can get around the bareword issue by simply quoting: "WM_DELETE_WINDOW".
        Thanks ichimunki, for the help on the bareword issue. And I agree with you - if you re-direct the close button, you should do something with it, rather than just ignoring the darn thing.

        Normally, I have my 'clean up' sub-routine right after the 'MainLoop', so if when they click on the close button it'll go there by default. This 'clean up' routine is also called by the 'Quit' button (or menu item).


        And on a completely different subject - I've found that when you try to plug someone's username into the reply, make sure you have their id right. Or else you get links to some interesting locations...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://161676]
Approved by jlk
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.