Python Forum
Review my code and Help me in Improving it. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Review my code and Help me in Improving it. (/thread-29382.html)



Review my code and Help me in Improving it. - Novak - Aug-31-2020

I was writing a GUI program in wxpython and at the completion of the program the window pops up for a split second and vanishes. Why?

import wx
class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None,
            pos=wx.DefaultPosition, size=wx.Size(450, 100),
            style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION |
             wx.CLOSE_BOX | wx.CLIP_CHILDREN,
            title="PyDa")
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        lbl = wx.StaticText(panel,
        label="Hello I am PyDa the Python Digital Assistant. How can I help you?")
        sizer.Add(lbl, 0, wx.ALL, 5)
        self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER,size=(400,30))
        self.txt.SetFocus()
        self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
        sizer.Add(self.txt, 0, wx.ALL, 5)
        panel.SetSizer(sizer)
        self.Show()

        def OnEnter(self, event):
            input = self.txt.GetValue()
            input = input.lower()
            print("It worked!")


        if __name__ == "__main__":
            app = wx.App(True)
            frame = MyFrame()
            app.MainLoop()



RE: Review my code and Help me in Improving it. - Larz60+ - Aug-31-2020

change line 28 from: app = wx.App(True)
to: app = wx.App(False)