加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

window – 在PyGTK中创建RGBA Colormap

发布时间:2020-12-14 05:26:42 所属栏目:Windows 来源:网络整理
导读:我有一个 Python 2.7和PyGTK的项目. 我需要创建一个透明的背景窗口,但仍然能够在窗口内显示图像(像素图和基于蒙版)和其他对象. 我使用以下代码,但没有图像对象出现在Ubuntu(Oneric Ocelot)中,我收到一个错误,发布在下面,(尽管窗口显示,其按钮对象).这甚至不
我有一个 Python 2.7和PyGTK的项目.

我需要创建一个透明的背景窗口,但仍然能够在窗口内显示图像(像素图和基于蒙版)和其他对象.

我使用以下代码,但没有图像对象出现在Ubuntu(Oneric Ocelot)中,我收到一个错误,发布在下面,(尽管窗口显示,其按钮对象).这甚至不会在Windows 7中呈现(此错误也发布在下面).

def expose(widget,event):
            cr = widget.window.cairo_create()

            # Sets the operator to clear which deletes everything below where an object is drawn
            cr.set_operator(cairo.OPERATOR_CLEAR)
            # Makes the mask fill the entire window
            cr.rectangle(0.0,0.0,*widget.get_size())
            # Deletes everything in the window (since the compositing operator is clear and mask fills the entire window
            cr.fill()
            # Set the compositing operator back to the default
            cr.set_operator(cairo.OPERATOR_OVER)

        hab_fish_win = gtk.Window()
        hab_fish_win.resize(640,480)
        hab_fish_win.set_resizable(False)
        hab_fish_win.set_decorated(False)
        hab_fish_win.set_has_frame(False)
        hab_fish_win.set_position(gtk.WIN_POS_CENTER)
        hab_fish_win.set_app_paintable(True)
        screen = hab_fish_win.get_screen()
        rgba = screen.get_rgba_colormap()
        hab_fish_win.set_colormap(rgba)
        hab_fish_win.connect('expose-event',expose)

        hab_fish_win.show()

WINDOWS 7 RUN:

Traceback (most recent call last): File “C:UsersuserMousePaw
GamesWord4WordPYMfishtest2.py”,line 337,in
HAB_FISH() File “C:UsersuserMousePaw GamesWord4WordPYMfishtest2.py”,line 100,in init
hab_fish_win.set_colormap(rgba) TypeError: Gtk.Widget.set_colormap() argument 1 must be gtk.gdk.Colormap,not
None

一个快速的“打印rgba”确认rgba是“无”,因此错误.

UBUNTU“ONERIC OCELOT”运行:

Gtk Warning: Attempt to draw a drawable with depth 24 to a drawable with depth 32

到底是怎么回事?我迫切需要窗户的透明背景.

解决方法

好的,经过数小时的研究,我发现Windows不支持这种透明性.至于Linux错误,我不知道.

我正在移植到PyGObject,并为我的目的使用另一种方法.我建议读者回答这个问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读