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
Version imprimable
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:
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:
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:
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()
J'ai résolu mon problème avec:
pour la fonction et en l'appelant avec:Code:
1
2
3
4
5 def OnOffButton(self, event, argument1, argument2): argument1.SetBitmapLabel(argument2) argument1.Refresh() argument1.Update() event.Skip()
Code:
1
2 self.button6.Bind(wx.EVT_LEAVE_WINDOW, lambda evt=wx.EVT_LEAVE_WINDOW, arg1=self.button6, arg2=image6 : self.OnOffButton(evt, arg1, arg2)) self.button6.Bind(wx.EVT_ENTER_WINDOW, lambda evt=wx.EVT_ENTER_WINDOW, arg1=self.button6, arg2=image6_on : self.OnOffButton(evt, arg1, arg2))
Merci beaucoup pour avoir retourné la solution même si personne ne t'as aidé, c'est un comportement exemplaire que malheureusement tout le monde n'a pas :/
Je suis sur que ca me servira un jour donc je sauvegarde ca bien au chaud, merci encore :king:
Bonjour,
J'ai vu ton travail pour utiliser des images dans des panels et je suis bloqué sur un truc qui est plus simple, je voudrais juste mettre un arrière plan dans des wx.panel
j'ai utilisé une portion de ton code ça marche plus ou moins, mais ça bloque après.
voici deux portion de code dans lesquels je veux mettre mon image comme arrière planIci ça bloque complètement dès le lancement de ma fenêtreCode:
1
2
3
4
5
6
7
8
9
10
11 panel_connexion = wx.Panel(self,wx.ID_ANY) background = 'planet.jpg' img = wx.Image(background, wx.BITMAP_TYPE_ANY) self.buffer = wx.BitmapFromImage(img) dc = wx.BufferedDC(wx.ClientDC(panel_connexion), self.buffer) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, evt): dc = wx.BufferedPaintDC(self, self.buffer)
Ici ça marche mais quand je minimise l'image disparaît et quand je ferme la fenêtre ça bloque sur la fenêtre précédente même si je n'ai pas mis d'arrière planCode:
1
2
3
4
5
6
7
8
9
10
11 def main_frame(self): #declaration de la fenetre principale f2=wx.Frame(self,-1,"Main frame",size=(600,500)); panel_diag = wx.Panel(f2,wx.ID_ANY) background = 'planet.jpg' img = wx.Image(background, wx.BITMAP_TYPE_ANY) self.buffer = wx.BitmapFromImage(img) dc = wx.BufferedDC(wx.ClientDC(panel_diag), self.buffer) self.Bind(wx.EVT_PAINT, self.OnPaint
Merci pour votre aide
Salut,
désolé de ne pas avoir vu ton post plus tôt ... dernièrement je ne me connecte plus trop souvent ...
Je ne comprends pas trop pourquoi tu as ces comportements ... Moi, voici comment je fais:
Je déclare d'abords mon panel:
Puis je l'appelle depuis la création de ma frame:Code:
1
2
3
4
5
6
7
8
9
10
11
12 class Panel1(wx.Panel): def __init__(self, parent, background): wx.Panel.__init__(self, parent, -1) repwork=os.path.dirname(sys.argv[0])+'\\' background = repwork+'Walls\\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, event): dc = wx.BufferedPaintDC(self, self.buffer)
et pour moi c'est bon ...Code:
1
2
3
4
5 class frame1(wx.Frame): def __init__(self, *args, **kwds): kwds["style"] = wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX) wx.Frame.__init__(self, size=(1000, 750), *args, **kwds) self.panel1 = Panel1(self, -1)