How do I create a canvas selection tool?

Go To


What I'm wanting to do is create a selection tool (like what you see in most paint programs) using PyGtk. I've seen a previous question that asked something similar, but they already seemed to know what they were doing to make the selection itself. That user said he was using an eventbox, but I don't know how I would use that to accomplish what I am trying to do. How would the eventbox work with a selection?

The algorithm for the rectangle isn't a problem at all, I just need to know what tools I should be using to actually select a part of a picture and be able to move it around. This is my first time using PyGtk, and I'm also fairly new to python itself, so any help would be great.

2012-04-04 20:29
by emikodo


If you want to display an image and allow the user to select and move parts of it, you best look for a ready-made image editing widget. GTK doesn't come with one.

To roll your own you can use an image widget for display, but it doesn't care about the mouse, so you can place it inside an event box and connect to button and movement events. You'll have to handle all the drawing of rectangle, walking ants and floating cutout yourself in the pixbuf backing the image.

It might be easier to start from scratch with an empty event box and draw even the image yourself.

2012-04-07 18:19
by Tobias