Bonjour,
Je voudrais savoir comment faire pour mettre une image en fond d'écran avec wxpython ... Et mettre bien sûr mes buttons, etc .. par dessus
Bonjour,
Je voudrais savoir comment faire pour mettre une image en fond d'écran avec wxpython ... Et mettre bien sûr mes buttons, etc .. par dessus
En fait, je viens de régler mon problème de fond d'écran en créant un panel de la sorte:
Par contre, maintenant j'ai un problème avec mes bitmap buttons. En fait, les images sont des .png qui sont sensés être transparants, mais là ils ne le sont pas ... Comment faire ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 class Panel1(wx.Panel): def __init__(self, parent, background): wx.Panel.__init__(self, parent, -1) background = 'background.jpg' img = wx.Image(background, wx.BITMAP_TYPE_ANY) self.buffer = wx.BitmapFromImage(img) dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, evt): dc = wx.BufferedPaintDC(self, self.buffer)
Je n'arrive pas à faire fonctionner les boutons transparents ... voici mon code:
Je ne vois pas ce qui cloche ....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 import wx class Panel1(wx.Panel): def __init__(self, parent, background): wx.Panel.__init__(self, parent, -1) background = 'background.jpg' img = wx.Image(background, wx.BITMAP_TYPE_ANY) self.buffer = wx.BitmapFromImage(img) dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, evt): dc = wx.BufferedPaintDC(self, self.buffer) def OnTimeToClose(self): print "salut!" frame1.Close() app = wx.PySimpleApp() frame1 = wx.Frame(None, -1, "An image on a panel", size=(800, 600)) panel1 = Panel1(frame1, -1) image1= wx.Bitmap("films.png",wx.BITMAP_TYPE_PNG) mask = wx.Mask(image1, wx.WHITE) image1.SetMask(mask) button1 = wx.BitmapButton(panel1, id=-1, bitmap=image1,pos=(10, 20), size = (imageFilm.GetWidth()+5, imageFilm.GetHeight()+5)) panel1.Bind(wx.EVT_BUTTON, OnTimeToClose, button1) frame1.Show(True) app.MainLoop()
C'est bizarre, j'ai repris le même script que les exemples wxpython, mais avec mes images et ça marche ... Par contre, mon code ci-dessus ne passe pas ... Vraiment personne n'aurait une idée ??
Bon, rien à faire ... Je ne trouve pas ...
Est-ce que quelqu'un saurait où je peux trouver un exemple avec un GUI qui aurait un fond d'écran (ou pas) et des boutons de forme elliptique qui changent de couleur qaund on clique dessus ...![]()
Bon, je crois que je commence à trouver ... Par contre, mon code passe bien (pour le changement d'image sur le bouton quand la souris est dessus) sous windows, mais pas sur LINUX qui est la machine ou tournera mon code :
Voyez-vous pourquoi ça ne passe pas sous LINUX ??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 # interactivebutton.py import wx import wx.lib.buttons as buttons class MyPanel(wx.Panel): def __init__(self, parent, ID): wx.Panel.__init__(self, parent, ID, wx.DefaultPosition) imageFilm= wx.Bitmap("films.png",wx.BITMAP_TYPE_PNG) self.btn = self.bitmap_button_1 = wx.BitmapButton(self, -1, bitmap=imageFilm) #self.btn.SetBezelWidth(1) self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, self.btn) self.btn.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterButton) self.btn.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveButton) def OnEnterButton(self, event): imageFilm= wx.Bitmap("films_on.png",wx.BITMAP_TYPE_PNG) self.btn = self.bitmap_button_1 = wx.BitmapButton(self, -1, bitmap=imageFilm) self.btn.Refresh() event.Skip() def OnLeaveButton(self, event): imageFilm= wx.Bitmap("films.png",wx.BITMAP_TYPE_PNG) self.btn = self.bitmap_button_1 = wx.BitmapButton(self, -1, bitmap=imageFilm) self.btn.Refresh() event.Skip() def OnTimeToClose(self, evt): frame.Destroy() class MyApp(wx.App): def OnInit(self): global frame frame = wx.Frame(None, -1, "interactivebutton.py", wx.DefaultPosition, wx.Size(800,600)) mypanel = MyPanel(frame, -1) frame.Centre() frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(0) app.MainLoop()
Partager