tear-off buttons for Tkinter Text objects?

Discussion in 'Python' started by Deacon Sweeney, Apr 6, 2004.

  1. Hi. I've embedded some buttons in a Text object, and I would like these
    buttons to perform a 'tear-off' of that line when clicked. That is, when the
    button is clicked, I would like a new Toplevel to appear with a new Text
    object which contains the text. Creating a 'pop-off' button, where the
    Toplevel appears at some predetermined (or calculatable) point would be
    easy, I'd just create the Toplevel, position it, and pass the info to it.
    The difference would be that the 'tear-off' button would automatically
    'grab' the new Toplevel so that it could be easily repositioned in the same
    motion of the mouse.

    There are three benefits to this that make it worthwhile. One, obviously
    repositioning is one mouse click easier. Two, I'll also add code to dock the
    lines, so re-docking a mistaken tear-off would be easier as well. Three, its
    just cool.

    So is there maybe some way to trick the window manager into thinking there's
    been a mouse click? It would be easy enough to position the title bar of the
    new Toplevel under the cursor. Or can the new window just be (magically)
    bound to the cursor until the button-pressing click is released? Any help
    would be appreciated.

    Thanks,

    Deacon Sweeney
     
    Deacon Sweeney, Apr 6, 2004
    #1
    1. Advertising

  2. Deacon Sweeney wrote:

    > Hi. I've embedded some buttons in a Text object, and I would like these
    > buttons to perform a 'tear-off' of that line when clicked. That is, when

    the
    > button is clicked, I would like a new Toplevel to appear with a new Text
    > object which contains the text. Creating a 'pop-off' button, where the
    > Toplevel appears at some predetermined (or calculatable) point would be
    > easy, I'd just create the Toplevel, position it, and pass the info to it.
    > The difference would be that the 'tear-off' button would automatically
    > 'grab' the new Toplevel so that it could be easily repositioned in the

    same
    > motion of the mouse.


    this approach should work:

    - add custom event handlers for button press, mouse motion, and button
    release.

    - in the button press handler, register the current mouse coordinates
    (relative to
    the root window), create the toplevel, and position it in a suitable
    location. also
    grab the mouse pointer (to make sure you get all mouse events)
    (autograbbing
    may take care of that, but a little explicitness never hurts)

    - in the mouse motion handler, calculate the difference between the current
    mouse position and the last registered position, and move the toplevel
    accordingly

    - in the mouse release handler, release the grab (if necessary)

    </F>
     
    Fredrik Lundh, Apr 16, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    0
    Views:
    470
    Steve
    Jan 31, 2006
  2. ishtar2020
    Replies:
    2
    Views:
    867
    Jim Segrave
    Apr 7, 2006
  3. zhouu

    How to Clean Tear Stains On a Dog

    zhouu, Feb 9, 2010, in forum: ASP .Net
    Replies:
    0
    Views:
    469
    zhouu
    Feb 9, 2010
  4. Chris Kennedy

    ASP Tear functionality

    Chris Kennedy, Jun 27, 2005, in forum: ASP General
    Replies:
    2
    Views:
    176
    Bullschmidt
    Jun 30, 2005
  5. dorayme
    Replies:
    16
    Views:
    852
    Jonathan N. Little
    Apr 4, 2012
Loading...

Share This Page