问题
Hey guys I've run into a problem that I don't know how to solve. I just met with a team to design a GUI in python using PyGtk.
I need to make a GUI that has clickable areas on screen. I need to divide the screen up into 12 equal areas with one square one in the centrer. Like this: http://imgur.com/PMT3m
I thought about using buttons but buttons are rectangular. Is it possible to make buttons that are a different shape like those show in the picture? If i can would those buttons resize if I changed the size of the window?
The other option that I thought of was to create an action listener that listens for mouse clicks, gathers the position data about the click and then calls the specific methods based on the region it was in. In this method I would need to use a static image as the background which is not that desirable. I would like to make it resistible if possible.
Has anyone done something like this before? If so what method did you use? I don't need some to write code for me I just need help getting started. Which method seems more sane? I do not have a lot of experience working with other python GUI tools so I am open to other suggestions such as pyQt or wxPython.
Thanks in advance!
回答1:
If you only need to get feedback of the click, then using a GtkDrawingArea
and listening there for mouse clicks would be enough. You won't need to use a static image for that, you can just use cairo and draw yourself the shape, based on the size of the drawing area, so that it always has the shape you want.
However, if you have planned to use massive mouse interaction there (drag and drop of shapes, etc.), then using a canvas like GooCanvas would be the preferred way to go.
Be also aware that pyGTK is for GTK 2 only, available under Linux and Windows, but it's obsoleted by pyGObject for GTK 3 (on Linux, as there's currently no official all-in-one installer of pyGObject for Windows).
To draw in a GtkDrawingArea
, you'll use the expose-event
signal on GTK 2, and the draw
signal on GTK 3.
来源:https://stackoverflow.com/questions/13826108/creating-clickable-areas-on-screen-with-pygtk