Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:58:04+00:00 2026-05-25T13:58:04+00:00

Can anyone help or point me in the right direction for figuring out how

  • 0

Can anyone help or point me in the right direction for figuring out how to create a drag and draw rectangular box to be used as a selection tool in PyGtk? I am presently using an event box with a drawable window and the user can click once in the upper left and once in the lower right corner of the portion of image they would like to choose which will then draw a rectangle over the selection, but a drag and draw rectangle will allow the user to better adjust and get better accuracy.

I have looked quite a few places for information or a tutorial on this but I haven’t found much. I am relatively new to Gtk+ so perhaps this is so simple that no one has to ask.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:58:05+00:00Added an answer on May 25, 2026 at 1:58 pm

    Actually, this doesn’t seem all that lamebrained at all. It is actually quite specific, and a little challenging.

    I’ll give you the steps to start you off, but as you’re beginning (and you didn’t post any specific code), it would be better for you to create the code yourself based on documentation and my hints.

    By the way, look up the official PyGTK documentation – that should be your definitive source for all the objects and functions of PyGTK. It is very well written and exhaustive, and I rarely have to look more than five minutes to find what I need.

    What I suggest you do is use three signals, connected to your drawing area.

    • button-press-event
    • button-release-event
    • motion-notify-event

    Create three callbacks (tutorial here), one for each event. Connect your drawing area to your events and callbacks (again, see tutorial. You may need to go through a few pages on it.).

    You are going to also need to create two boolean variables on the global level (above the main class, at the same level you import modules.) The first controls whether the selection tool is chosen (call it “Select_On”), and the second for if it is active (call it “Select_Active”)

    On the button you use to start the select tool, set “Select_On” to “True”. This should probably be a toggle button, so make sure you set it up so “Select_On” gets set to off if you toggle the button off.

    On button-press-event, create the object for selecting. What you’re going with now actually should work well. Also, set “Select_Active” to “True”.

    On motion-notify-event, change the size of your object based on cursor position. Refer to that documentation for that particular kind of object to learn how to change its size, and refer here for how to get the cursor position.

    Be prepared to write an algorithm to determine how to change the size of the selection object based on the cursor position. If you need help with that, feel free to ask for it in a separate question.

    On button-release-event, set “Select_Active” to “False”, and call all your code for actually confirming the selection.

    As an aside, the benefit to using the “motion-notify-event” is that, as soon as the cursor leaves the widget you’re selection in, the selection box stops changes sizes. The cursor must re-enter the widget to continue changing the selection box size.

    I hope all that works for you, and wishing you the very best on your project!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help point me in the right direction of how I might be
Can anyone help point me in the right direction - I have the following
I wonder if anyone can help me or point me in the right direction.
can anyone help me with my problem. I need to create a sql rule
Not sure really where to start with this one. Can anyone help/point me in
Can anyone help me with the trying to write SQL (MS SqlServer) - I
Can anyone help with with the time complexity of this algorithm, and why it
Can anyone help? I have been designing a site using Javascript but the rest
can anyone help me in trying to check whether JavaScript is enabled in client
Can anyone help? I have been using the entity framework and its going well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.