2011-02-03 10 views
6

मैं पीजीजीटीके का उपयोग करके कोई सजावट और एक पारदर्शी पृष्ठभूमि वाली खिड़की बनाने के लिए वास्तव में कड़ी मेहनत कर रहा हूं। फिर मैं काहिरा के साथ खिड़की की सामग्री खींचूँगा। लेकिन मैं इसे काम नहीं कर सकता।पीईजीटीके और पायकेयरो के साथ विंडो में पारदर्शी पृष्ठभूमि कैसे प्राप्त करें?

मैं अलग अलग तरीकों का एक बहुत कोशिश की है, वे सब विफल रहा है, यह उन्हें

#!/usr/bin/env python 

import pygtk 
pygtk.require('2.0') 
import gtk, sys, cairo 

win = None 

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

    #Start drawing 
    cr.set_operator(cairo.OPERATOR_CLEAR) 
    cr.set_source_rgba(0.5,1.0,0.0,0.5) 
    cr.rectangle(0, 0, 0.9, 0.8) 
    cr.fill() 

def main (argc): 
    global win 

    win = gtk.Window() 

    win.set_decorated(False) 

    win.connect('delete_event', gtk.main_quit) 
    win.connect('expose-event', expose) 

    win.set_app_paintable(True) 

    win.show() 

    gtk.main() 

if __name__ == '__main__': 
    sys.exit(main(sys.argv)) 

तो में से एक है, क्या यह करने के लिए सबसे आसान तरीका है?

उत्तर

9

तो, मैंने वास्तव में इसे स्वयं बाहर निकाला।

यह एक कामकाजी उदाहरण है। मैंने प्रासंगिक भागों पर टिप्पणी की है अगर किसी और को यह कैसे करना है में रुचि है।

#!/usr/bin/env python 

import pygtk 
pygtk.require('2.0') 
import gtk, sys, cairo 
from math import pi 

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) 

    # Draw a fancy little circle for demonstration purpose 
    cr.set_source_rgba(0.5,1.0,0.0,1) 
    cr.arc(widget.get_size()[0]/2,widget.get_size()[1]/2, 
      widget.get_size()[0]/2,0,pi*2) 
    cr.fill() 

def main (argc): 

    win = gtk.Window() 

    win.set_decorated(False) 

    # Makes the window paintable, so we can draw directly on it 
    win.set_app_paintable(True) 
    win.set_size_request(100, 100) 

    # This sets the windows colormap, so it supports transparency. 
    # This will only work if the wm support alpha channel 
    screen = win.get_screen() 
    rgba = screen.get_rgba_colormap() 
    win.set_colormap(rgba) 

    win.connect('expose-event', expose) 

    win.show() 
0

एक समस्या में सही समस्या को संबोधित किया गया है। लेकिन यह सी ++ में है। इसे समझने की कोशिश करो।

इस का पालन करें: Linux Questions

टिप्पणी phorgan1 द्वारा पोस्ट की गई देखें। उम्मीद है कि यह मदद करता है ....

+0

यह कोड उपरोक्त मेरे कोड जैसा दिखता है। मैंने अपना कोड बदलकर सी ++ कोड के अनुसार बदल दिया, लेकिन यह या तो काम नहीं करता है। – paldepind

संबंधित मुद्दे