使用PyGtk在屏幕上创建可点击区域 [英] Creating Clickable areas on screen with PyGtk

查看:222
本文介绍了使用PyGtk在屏幕上创建可点击区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个我不知道如何解决的问题。我刚刚遇到一个团队,使用PyGtk设计一个GUI。

我需要制作一个GUI,屏幕上有可点击的区域。我需要把屏幕分成12个相等的区域,中间有一个平方。像这样: http://imgur.com/PMT3m



<我想过使用按钮,但按钮是矩形的。是否可以制作与图片中显示的形状不同的按钮?如果我可以改变这些按钮的大小,如果我改变了窗口的大小?



我想到的另一个选择是创建一个侦听鼠标点击的动作侦听器,收集关于点击的位置数据,然后根据它所在的区域调用特定的方法。在这种方法中,我需要使用静态图像作为背景,这不是那么理想。如果可能的话,我想让它具有抵抗性。



以前有人做过这样的事吗?如果是的话,你使用了什么方法?我不需要一些人为我写代码我只需要帮助入门。哪种方法似乎更理智?我没有很多使用其他python GUI工具的经验,所以我接受其他建议,例如pyQt或wxPython。



如果您只需要获取点击的反馈,然后使用 GtkDrawingArea 并在那里监听鼠标点击就足够了。你不需要为此使用静态图像,你可以使用开罗,并根据绘制区域的大小,以便它始终具有您想要的形状。



但是,如果您计划使用大量的鼠标交互(拖放形状等),然后使用像 GooCanvas 这样的画布将是首选的方式。



请注意,pyGTK仅适用于GTK 2,可在Linux和Windows下使用,但pyGObject对于GTK 3已经过时了(在Linux上,因为目前没有官方的一体机为了绘制 GtkDrawingArea ,您将使用在GTK 2上显示事件信号,在GTK 3上显示绘制信号。


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!

解决方案

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.

这篇关于使用PyGtk在屏幕上创建可点击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆