#1 Le 06/04/2014, à 13:54
- g_barthe
[Résolu] wxpython données d'une fenêtre à une autre
Bonjour,
J'ai créé une fenêtre avec des calculs et je voudrais mettre le résultat de ces calculs en graphique.
J'utilise wxpython pour l'interface. J'ai bien ma fenêtre qui fait tous les calculs que je veux mais après j'ai du mal à transmettre les résultats à ma fenêtre qui va faire les graphiques via la lib wx.lib.plot.
Je pense que je passe à côté d'un truc tout simple.
Merci du petit coup de main.
Dernière modification par g_barthe (Le 20/04/2014, à 21:38)
Mon forum perso sur le génie climatique http://le-genie-climatique.positifforum.com/
Le forum des travaux manuels : http://pausebroderie.fr/
Hors ligne
#2 Le 12/04/2014, à 15:45
- bipede
Re : [Résolu] wxpython données d'une fenêtre à une autre
Voici un petit exemple de passage de données entre fenêtres...
#! /usr/bin/env python
#-*- coding: utf8 -*-
import wx
from random import randint
class CalcFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title=u"Fenêtre de calcul")
self.resultat = None
self.affichage = None
sizer = wx.BoxSizer(wx.VERTICAL)
sizerButtons = wx.BoxSizer(wx.VERTICAL)
bt1 = wx.Button(self, -1, u"Bouton pour calculer un résultat et l'afficher dans une autre fenêtre")
bt2 = wx.Button(self, -1, u"Bouton pour quitter l'application")
sizerButtons.Add(bt1, 1, wx.EXPAND|wx.BOTTOM, 5)
sizerButtons.Add(bt2, 1, wx.EXPAND)
sizer.Add(sizerButtons, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
self.Fit()
self.Bind(wx.EVT_BUTTON, self.OnCalc, bt1)
self.Bind(wx.EVT_BUTTON, self.OnQuit, bt2)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
def OnCalc(self, event):
loto = []
while len(loto) < 5:
tirage = randint(1, 49)
if tirage not in loto:
loto.append(tirage)
self.resultat = loto
if not self.affichage:
self.affichage = DisplayFrame(self)
self.affichage.Show()
self.affichage.SetResultat(self.resultat)
def OnQuit(self, event):
if self.affichage:
self.affichage.Destroy()
self.Destroy()
def DetachDisplay(self):
self.affichage = None
class DisplayFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, title=u"Fenêtre de résultat")
sizer = wx.BoxSizer(wx.VERTICAL)
sizerLabel = wx.BoxSizer(wx.VERTICAL)
label1 = wx.StaticText(self, -1, u"Les résultats du loto sont les suivants:")
self.label2 = wx.StaticText(self, -1, u" ")
sizerLabel.Add(label1, 1, wx.BOTTOM, 5)
sizerLabel.Add(self.label2, 1)
sizer.Add(sizerLabel, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizer(sizer)
self.SetAutoLayout(True)
self.Fit()
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnClose(self, event):
self.GetParent().DetachDisplay()
self.Destroy()
def SetResultat(self, result):
count = 0
libelle = ""
result.sort()
for number in result:
count += 1
libelle = libelle + str(number)
if count < 5:
libelle += " - "
self.label2.SetLabel(libelle)
class TestApp(wx.App):
def OnInit(self):
f = CalcFrame()
self.SetTopWindow(f)
f.Show(True)
return True
app = TestApp()
app.MainLoop()
Desktop: MSI - Intel® Core™ i5-3330 CPU @ 3.00GHz × 4 - RAM 8 go- Kubuntu 21.04 - Système sur SSD 64 Go - /home sur HDD 500 Go.
Laptop: DELL Inspiron-15 3567 - Intel® Core™ i5-7200 CPU @ 2.50GHz × 4 - RAM 8 go - HDD 1 To - Ubuntu 20.10 avec /home séparé.
Mon site: Les contributions du bipède
Hors ligne
#3 Le 13/04/2014, à 18:24
- g_barthe
Re : [Résolu] wxpython données d'une fenêtre à une autre
merci je teste ça prochainement.
Mon forum perso sur le génie climatique http://le-genie-climatique.positifforum.com/
Le forum des travaux manuels : http://pausebroderie.fr/
Hors ligne
#4 Le 20/04/2014, à 21:38
- g_barthe
Re : [Résolu] wxpython données d'une fenêtre à une autre
ca marche impec. J'ai pigé le truc.
Merci encore.
Mon forum perso sur le génie climatique http://le-genie-climatique.positifforum.com/
Le forum des travaux manuels : http://pausebroderie.fr/
Hors ligne