2010-03-03 2 views
1

Je veux colorier l'arrière-plan (SetBackgroundColour) d'un wx.Panel avec un dégradé bleu à noir.Comment faire un dregradê sur wx.Panel Background?

Comment puis-je le faire?

+0

Curiosité: dans quelle langue est-il appelé « Dégradé »? (Je sais qu'en français ça s'appelle "dégradé".) – tzot

+0

en portugais :) –

Répondre

5

Adapté de DaniWeb:

import wx 

class MyFrame(wx.Frame): 
    def __init__(self, parent=None, title=None): 
     wx.Frame.__init__(self, parent, wx.ID_ANY, title) 
     self.panel = wx.Panel(self, size=(350, 450)) 
     # this sets up the painting canvas 
     self.panel.Bind(wx.EVT_PAINT, self.on_paint) 
     # set frame size to fit panel 
     self.Fit() 

    def on_paint(self, event): 
     # establish the painting canvas 
     dc = wx.PaintDC(self.panel) 
     x = 0 
     y = 0 
     w, h = self.GetSize() 
     dc.GradientFillLinear((x, y, w, h), 'blue', 'black') 


app = wx.App(0) 
MyFrame(title='Gradient Test').Show() 
app.MainLoop() 

Et une autre façon de générer un bitmap de gradient, en utilisant NumPy (de wxpython.org):

import numpy as np 

def GetBitmap(self, width=640, height=480, leftColour=(255,128,0), rightColour=(64,0,255)): 
     ## Create a horizontal gradient 
     array = np.zeros((height, width, 3),'uint8') 
     # alpha is a one dimensional array with a linear gradient from 0.0 to 1.0 
     alpha = np.linspace(0., 1., width) 
     # This uses alpha to linearly interpolate between leftColour and rightColour 
     colourGradient = np.outer(alpha, leftColour) + np.outer((1.-alpha), rightColour) 
     # NumPy's broadcasting rules will assign colourGradient to every row of the destination array 
     array[:,:,:] = colourGradient 
     image = wx.EmptyImage(width,height) 
     image.SetData(array.tostring()) 
     return image.ConvertToBitmap()# wx.BitmapFromImage(image) 
+0

merci m8, vous étiez très rapide! Connaissez-vous la réponse pour cette autre question: http://stackoverflow.com/questions/2375613/is-it-possible-to-dock-wx-auimanager-panes-onto-tops-bottoms-of-another -pans –