Switch windows in wxpython without destroying the previous one

Asked

Viewed 26 times

1

Good afternoon, I’m new to Wxpython and I’m only trying to have the "frame1" registration update the window to the Mainframe that will mount a Pie Chart. I don’t want the window to be destroyed, just to update the first.

class MainFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, size=(800, 580))

        # Add SplitterWindow panels
        self.split_win = wx.SplitterWindow(self)
        self.top_split = MatplotPanel(self.split_win)
        self.bottom_split = wx.Panel(self.split_win, style=wx.SUNKEN_BORDER)
        self.split_win.SplitHorizontally(self.top_split, self.bottom_split, 480)

        # Add some contrls/widgets (StaticText and Buttons)
        # Add Text control to the bottom_split window
        self.text1 = wx.StaticText(self.bottom_split, -1, u"You can also plot from file", size=(250, 30), pos=(510, 10),
                                   style=wx.ALIGN_CENTER)
        self.text1.SetBackgroundColour('Gray')
        font = wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL)
        self.text1.SetFont(font)

        # Add Buttons to the bottom_split window and bind them to plot functions
        self.Button1 = wx.Button(self.bottom_split, -1, "Plot1", size=(80, 40), pos=(10, 10))
        self.Button1.Bind(wx.EVT_BUTTON, self.plot1)

        self.Button2 = wx.Button(self.bottom_split, -1, "Plot2", size=(80, 40), pos=(110, 10))
        self.Button2.Bind(wx.EVT_BUTTON, self.plot2)

        self.Button3 = wx.Button(self.bottom_split, -1, "Plot3", size=(80, 40), pos=(210, 10))
        self.Button3.Bind(wx.EVT_BUTTON, self.plot3)


def plot1(self, event):
    pass


def plot2(self, event):
    pass


def plot3(self, event):
    pass


def plot4(self, event):
    pass


def plot5(self, event):
    pass


class MatplotPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, size=(50, 50))

        self.figure = Figure()

    # Pie chart, where the slices will be ordered and plotted counter-clockwise:
        labels = 'a', 'b', 'c'
        sizes = [15, 35, 50]
        explode = (0, 0, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')

        fig1, ax1 = plt.subplots()
        ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
            shadow=True, startangle=90)
        ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

        plt.show()
        self.canvas = FigureCanvas(self, -1, self.figure)


class MyFrame1(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
                          size=wx.Size(496, 658), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
        self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT))

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        self.m_staticText12 = wx.StaticText(self, wx.ID_ANY, u"Qual sua faixa etária?", wx.DefaultPosition,
                                            wx.DefaultSize, 0)
        self.m_staticText12.Wrap(-1)

        bSizer1.Add(self.m_staticText12, 0, wx.ALL, 5)

        m_comboBox11Choices = [u"Abaixo de 25 anos", u"25 até 40 anos", u"41 até 55 anos", u"Acima de 56 anos"]
        self.m_comboBox11 = wx.ComboBox(self, wx.ID_ANY, u"Abaixo de 25 anos", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox11Choices, 0)
        self.m_comboBox11.SetSelection(0)
        bSizer1.Add(self.m_comboBox11, 0, wx.ALL, 5)

        self.m_staticText13 = wx.StaticText(self, wx.ID_ANY,
                                            u"Qual Percentual do seu patrimônio está investido?(Carros, casa, ações, etc)",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText13.Wrap(-1)

        bSizer1.Add(self.m_staticText13, 0, wx.ALL, 5)

        m_comboBox12Choices = [u"Até 25% ", u"Entre 26% e 50%", u"Entre 51% e 75%", u"Mais de 76% "]
        self.m_comboBox12 = wx.ComboBox(self, wx.ID_ANY, u"Até 25% ", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox12Choices, 0)
        self.m_comboBox12.SetSelection(0)
        bSizer1.Add(self.m_comboBox12, 0, wx.ALL, 5)

        self.m_staticText14 = wx.StaticText(self, wx.ID_ANY, u"Qual o objetivo dos seus investimentos?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText14.Wrap(-1)

        bSizer1.Add(self.m_staticText14, 0, wx.ALL, 5)

        m_comboBox13Choices = [u"Aposentadoria  ", u"Proteção do capital   ", u"Compra de um bem  ",
                               u"Crescimento significativo do patrimônio "]
        self.m_comboBox13 = wx.ComboBox(self, wx.ID_ANY, u"Aposentadoria  ", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox13Choices, 0)
        self.m_comboBox13.SetSelection(0)
        bSizer1.Add(self.m_comboBox13, 0, wx.ALL, 5)

        self.m_staticText15 = wx.StaticText(self, wx.ID_ANY,
                                            u"Como você se sentiria caso verificasse perdas em seus investimentos?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText15.Wrap(-1)

        bSizer1.Add(self.m_staticText15, 0, wx.ALL, 5)

        m_comboBox14Choices = [u"Extremamente desanimado. Não quero passar nunca por essa situação",
                               u"Moderadamente desanimado. Posso passar por essa situação, mas não gostaria",
                               u"Levemente desanimado. Entendo que a perda faz parte do processo de investimento",
                               u"Normal. Tudo bem passar por isso"]
        self.m_comboBox14 = wx.ComboBox(self, wx.ID_ANY,
                                        u"Extremamente desanimado. Não quero passar nunca por essa situação",
                                        wx.DefaultPosition, wx.DefaultSize, m_comboBox14Choices, 0)
        self.m_comboBox14.SetSelection(0)
        bSizer1.Add(self.m_comboBox14, 0, wx.ALL, 5)

        self.m_staticText16 = wx.StaticText(self, wx.ID_ANY,
                                            u"Quais são as aplicações financeiras em que você tem experiência?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText16.Wrap(-1)

        bSizer1.Add(self.m_staticText16, 0, wx.ALL, 5)

        m_comboBox15Choices = [u"Não Possuo", u"Renda Fixa", u"Renda Fixa e Ações de Longo Prazo",
                               u"Outras além das anteriores"]
        self.m_comboBox15 = wx.ComboBox(self, wx.ID_ANY, u"Não Possuo", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox15Choices, 0)
        self.m_comboBox15.SetSelection(0)
        bSizer1.Add(self.m_comboBox15, 0, wx.ALL, 5)

        self.m_staticText17 = wx.StaticText(self, wx.ID_ANY, u"Possui algum conhecimento sobre o mercado financeiro?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText17.Wrap(-1)

        bSizer1.Add(self.m_staticText17, 0, wx.ALL, 5)

        m_comboBox16Choices = [u"Não", u"Pouco", u"Médio", u"Bastante"]
        self.m_comboBox16 = wx.ComboBox(self, wx.ID_ANY, u"Não", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox16Choices, 0)
        self.m_comboBox16.SetSelection(0)
        bSizer1.Add(self.m_comboBox16, 0, wx.ALL, 5)

        self.m_staticText18 = wx.StaticText(self, wx.ID_ANY, u"Qual sua escoladidade?", wx.DefaultPosition,
                                            wx.DefaultSize, 0)
        self.m_staticText18.Wrap(-1)

        bSizer1.Add(self.m_staticText18, 0, wx.ALL, 5)

        m_comboBox17Choices = [u"Ensino fundamental ou inferior", u"Ensino Médio ", u"Ensino Superior",
                               u"Maior que Ensino Superior"]
        self.m_comboBox17 = wx.ComboBox(self, wx.ID_ANY, u"Ensino fundamental ou inferior", wx.DefaultPosition,
                                        wx.DefaultSize, m_comboBox17Choices, 0)
        self.m_comboBox17.SetSelection(0)
        bSizer1.Add(self.m_comboBox17, 0, wx.ALL, 5)

        self.m_staticText19 = wx.StaticText(self, wx.ID_ANY, u"Você costuma operar financeiramente com que frequência?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText19.Wrap(-1)

        bSizer1.Add(self.m_staticText19, 0, wx.ALL, 5)

        m_comboBox18Choices = [u"Pouquíssima", u"Pouca", u"Média", u"Alta"]
        self.m_comboBox18 = wx.ComboBox(self, wx.ID_ANY, u"Pouquíssima", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox18Choices, 0)
        self.m_comboBox18.SetSelection(0)
        bSizer1.Add(self.m_comboBox18, 0, wx.ALL, 5)

        self.m_staticText20 = wx.StaticText(self, wx.ID_ANY, u"Você pretende ter aumento de despesas no futuro?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText20.Wrap(-1)

        bSizer1.Add(self.m_staticText20, 0, wx.ALL, 5)

        m_comboBox19Choices = [u"Não. Pretendo diminuir", u"Não. Pretendo ter as mesmas que tenho hoje",
                               u"Sim. Pretendo aumentar ", u"Sim. Pretendo ter um grande aumento"]
        self.m_comboBox19 = wx.ComboBox(self, wx.ID_ANY, u"Não. Pretendo diminuir", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox19Choices, 0)
        self.m_comboBox19.SetSelection(0)
        bSizer1.Add(self.m_comboBox19, 0, wx.ALL, 5)

        self.m_staticText21 = wx.StaticText(self, wx.ID_ANY,
                                            u"Por quanto tempo você deseja manter seu dinheiro aplicado?",
                                            wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText21.Wrap(-1)

        bSizer1.Add(self.m_staticText21, 0, wx.ALL, 5)

        m_comboBox20Choices = [u"Menos de 1 ano", u"De 1 até 2 anos", u"De 2 até 3 anos", u"Mais de 3 anos"]
        self.m_comboBox20 = wx.ComboBox(self, wx.ID_ANY, u"Menos de 1 ano", wx.DefaultPosition, wx.DefaultSize,
                                        m_comboBox20Choices, 0)
        self.m_comboBox20.SetSelection(0)
        bSizer1.Add(self.m_comboBox20, 0, wx.ALL, 5)

        self.m_button3 = wx.Button(self, wx.ID_ANY, u"Cadastrar", wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer1.Add(self.m_button3, 0, wx.ALL | wx.ALIGN_RIGHT, 5)

        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.m_button3.Bind(wx.EVT_BUTTON, self.save)

    def __del__(self):
        pass

    # Virtual event handlers, overide them in your derived class
    def save(self, event):
        x = [self.m_comboBox11.GetSelection(),
             self.m_comboBox12.GetSelection(),
             self.m_comboBox13.GetSelection(),
             self.m_comboBox14.GetSelection(),
             self.m_comboBox15.GetSelection(),
             self.m_comboBox16.GetSelection(),
             self.m_comboBox17.GetSelection(),
             self.m_comboBox18.GetSelection(),
             self.m_comboBox19.GetSelection(),
             self.m_comboBox20.GetSelection()]
        y = np.array([self.m_comboBox11.GetValue(),
                      self.m_comboBox12.GetValue(),
                      self.m_comboBox13.GetValue(),
                      self.m_comboBox14.GetValue(),
                      self.m_comboBox15.GetValue(),
                      self.m_comboBox16.GetValue(),
                      self.m_comboBox17.GetValue(),
                      self.m_comboBox18.GetValue(),
                      self.m_comboBox19.GetValue(),
                      self.m_comboBox20.GetValue()
                      ])
        df = pd.DataFrame(y)
        print(x)
        print(y)
        frame.Destroy()

        event.Skip()


app = wx.App()
frame = MyFrame1(None)
frame.Show()
app.MainLoop()
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.