Creating new form

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating new form

Dionatan Moretti
Hello !

Sorry if I write something wrong... I'm not good in english...

I'm trying to do some app with a menu using wxPython...
When I click on a menuitem, i need that open a new form... but i dont know how to do this...
I'm trying:

class SecondFrame ( wx.Frame ):

      def __init__(self):
           wx.Frame.__init__(self, None, title="Second Frame")
           panel = wx.Panel(self)
           txt = wx.StaticText(panel, label="I'm the second frame!")
       

class MyFrame2 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 601,473 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
self.m_mgr = wx.aui.AuiManager()
self.m_mgr.SetManagedWindow( self )
self.m_mgr.SetFlags(wx.aui.AUI_MGR_DEFAULT)
self.m_menubar2 = wx.MenuBar( 0 )
self.m_menu5 = wx.Menu()
self.m_menuItem8 = wx.MenuItem( self.m_menu5, wx.ID_ANY, u"Exportador", u"Exporta os arquivos da Base Local para Base Remota", wx.ITEM_NORMAL )
self.m_menu5.AppendItem( self.m_menuItem8 )
self.m_menuItem9 = wx.MenuItem( self.m_menu5, wx.ID_ANY, u"Integrador App", u"Aguarda chegada de Pedidos do Aplicativo", wx.ITEM_NORMAL )
self.m_menu5.AppendItem( self.m_menuItem9 )
self.m_menubar2.Append( self.m_menu5, u"Integrador" ) 
self.m_menu12 = wx.Menu()
self.m_menuItem10 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Zerar Bonus Cliente", u"Zera bonus de cliente especifico", wx.ITEM_NORMAL )
self.m_menu12.AppendItem( self.m_menuItem10 )
self.m_menuItem11 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Adicionar Bonus Cliente", u"Adiciona bonus para cliente especifico", wx.ITEM_NORMAL )
self.m_menu12.AppendItem( self.m_menuItem11 )
self.m_menuItem12 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Modificar Bonus Cliente", u"Modifica valor do bonus de cliente especifico", wx.ITEM_NORMAL )
self.m_menu12.AppendItem( self.m_menuItem12 )
self.m_menubar2.Append( self.m_menu12, u"Manutencao" ) 
self.m_config = wx.Menu()
self.m_menuItem3 = wx.MenuItem( self.m_config, wx.ID_ANY, u"Base de Dados", u"Configuração da Base de Dados", wx.ITEM_NORMAL )
self.m_config.AppendItem( self.m_menuItem3 )
self.m_menuItem4 = wx.MenuItem( self.m_config, wx.ID_ANY, u"Horarios Funcionamento", u"Configura horário de funcionamento do Delivery", wx.ITEM_NORMAL )
self.m_config.AppendItem( self.m_menuItem4 )
self.m_menuItem7 = wx.MenuItem( self.m_config, wx.ID_ANY, u"E-Mails de Segurança", u"Cadastra e-mails de seguranças para caso de \"emergência\"", wx.ITEM_NORMAL )
self.m_config.AppendItem( self.m_menuItem7 )
self.m_menubar2.Append( self.m_config, u"Configurações" ) 
self.m_menu2 = wx.Menu()
self.m_menubar2.Append( self.m_menu2, u"Sobre" ) 
self.m_menu3 = wx.Menu()
self.m_menubar2.Append( self.m_menu3, u"Sair" ) 
self.SetMenuBar( self.m_menubar2 )
self.m_statusBar2 = self.CreateStatusBar( 1 )
self.m_mgr.Update()
self.Centre( wx.BOTH )
# Connect Events
self.Bind( wx.EVT_MENU, self.onMyFrame3, id = self.m_menuItem9.GetId() )
# Virtual event handlers, overide them in your derived class
def onMyFrame3( self, event ):
                frame = SecondFrame()
                frame.Show()

def __del__( self ):
self.m_mgr.UnInit()

app = wx.App(False)
frame = MyFrame2(None)
frame.Show(True)
app.MainLoop()

-------------------------------------------------------------------------------------
When I try to compile and run, python returns the following message:
Error: inconsistent indentation detected !

And shows this lines:

def onMyFrame3( self, event ):
                frame = SecondFrame()
                frame.Show()

But if I try:

def onMyFrame3( self, event ):
                event.Skip()

it doesnt return error... 
What i'm doing wrong ??

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Creating new form

a.link
That's because you use whitespace for indentation in `onMyFrame3()`, while rest of code uses tabs. You can see this in Notepad++: Menu bar > View > Show Symbols > Show White Space and TAB (tabs will be shown with arrows and space with dots).

On Saturday, October 27, 2018 at 10:09:23 PM UTC+3, Dionatan Moretti wrote:
Hello !

Sorry if I write something wrong... I'm not good in english...

I'm trying to do some app with a menu using wxPython...
When I click on a menuitem, i need that open a new form... but i dont know how to do this...
I'm trying:

class SecondFrame ( wx.Frame ):

      def __init__(self):
           wx.Frame.__init__(self, None, title="Second Frame")
           panel = wx.Panel(self)
           txt = wx.StaticText(panel, label="I'm the second frame!")
       

class MyFrame2 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 601,473 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
self.m_mgr = wx.aui.AuiManager()
self.m_mgr.SetManagedWindow( self )
self.m_mgr.SetFlags(wx.aui.AUI_MGR_DEFAULT)
self.m_menubar2 = wx.MenuBar( 0 )
self.m_menu5 = wx.Menu()
self.m_menuItem8 = wx.MenuItem( self.m_menu5, wx.ID_ANY, u"Exportador", u"Exporta os arquivos da Base Local para Base Remota", wx.ITEM_NORMAL )
self.m_menu5.AppendItem( self.m_menuItem8 )
self.m_menuItem9 = wx.MenuItem( self.m_menu5, wx.ID_ANY, u"Integrador App", u"Aguarda chegada de Pedidos do Aplicativo", wx.ITEM_NORMAL )
self.m_menu5.AppendItem( self.m_menuItem9 )
self.m_menubar2.Append( self.m_menu5, u"Integrador" ) 
self.m_menu12 = wx.Menu()
self.m_menuItem10 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Zerar Bonus Cliente", u"Zera bonus de cliente especifico", wx.ITEM_NORMAL )
self.m_menu12.AppendItem( self.m_menuItem10 )
self.m_menuItem11 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Adicionar Bonus Cliente", u"Adiciona bonus para cliente especifico", wx.ITEM_NORMAL )
self.m_menu12.AppendItem( self.m_menuItem11 )
self.m_menuItem12 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Modificar Bonus Cliente", u"Modifica valor do bonus de cliente especifico", wx.ITEM_NORMAL )
self.m_menu12.AppendItem( self.m_menuItem12 )
self.m_menubar2.Append( self.m_menu12, u"Manutencao" ) 
self.m_config = wx.Menu()
self.m_menuItem3 = wx.MenuItem( self.m_config, wx.ID_ANY, u"Base de Dados", u"Configuração da Base de Dados", wx.ITEM_NORMAL )
self.m_config.AppendItem( self.m_menuItem3 )
self.m_menuItem4 = wx.MenuItem( self.m_config, wx.ID_ANY, u"Horarios Funcionamento", u"Configura horário de funcionamento do Delivery", wx.ITEM_NORMAL )
self.m_config.AppendItem( self.m_menuItem4 )
self.m_menuItem7 = wx.MenuItem( self.m_config, wx.ID_ANY, u"E-Mails de Segurança", u"Cadastra e-mails de seguranças para caso de \"emergência\"", wx.ITEM_NORMAL )
self.m_config.AppendItem( self.m_menuItem7 )
self.m_menubar2.Append( self.m_config, u"Configurações" ) 
self.m_menu2 = wx.Menu()
self.m_menubar2.Append( self.m_menu2, u"Sobre" ) 
self.m_menu3 = wx.Menu()
self.m_menubar2.Append( self.m_menu3, u"Sair" ) 
self.SetMenuBar( self.m_menubar2 )
self.m_statusBar2 = self.CreateStatusBar( 1 )
self.m_mgr.Update()
self.Centre( wx.BOTH )
# Connect Events
self.Bind( wx.EVT_MENU, self.onMyFrame3, id = self.m_menuItem9.GetId() )
# Virtual event handlers, overide them in your derived class
def onMyFrame3( self, event ):
                frame = SecondFrame()
                frame.Show()

def __del__( self ):
self.m_mgr.UnInit()

app = wx.App(False)
frame = MyFrame2(None)
frame.Show(True)
app.MainLoop()

-------------------------------------------------------------------------------------
When I try to compile and run, python returns the following message:
Error: inconsistent indentation detected !

And shows this lines:

def onMyFrame3( self, event ):
                frame = SecondFrame()
                frame.Show()

But if I try:

def onMyFrame3( self, event ):
                event.Skip()

it doesnt return error... 
What i'm doing wrong ??

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Creating new form

GadgetSteve
In reply to this post by Dionatan Moretti

Sorry for top posting – this version of Outlook is a pain on that.

 

Dionatan,

 

From your code below it looks like you are mixing tabs and spaces – set your editor to use only spaces and to substitute 4 spaces for tab, (most programming editors have a setting for this and be sure to use one editors such as WordPad, NotePad, etc.  can do some horrible things to your code). Then make sure that all code is indented by multiples of 4 spaces with the indenting reflecting the scope.

 

Hope that helps.

 

Steve

 

From: [hidden email] <[hidden email]> On Behalf Of Dionatan Moretti
Sent: 27 October 2018 16:27
To: wxPython-users <[hidden email]>
Subject: [wxPython-users] Creating new form

 

Hello !

 

Sorry if I write something wrong... I'm not good in english...

 

I'm trying to do some app with a menu using wxPython...

When I click on a menuitem, i need that open a new form... but i dont know how to do this...

I'm trying:

 

class SecondFrame ( wx.Frame ):

 

      def __init__(self):    

           wx.Frame.__init__(self, None, title="Second Frame")

           panel = wx.Panel(self)

           txt = wx.StaticText(panel, label="I'm the second frame!")

                                                         

 

class MyFrame2 ( wx.Frame ):

            

             def __init__( self, parent ):

                            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 601,473 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

                           

                            self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

                            self.m_mgr = wx.aui.AuiManager()

                            self.m_mgr.SetManagedWindow( self )

                            self.m_mgr.SetFlags(wx.aui.AUI_MGR_DEFAULT)

                           

                            self.m_menubar2 = wx.MenuBar( 0 )

                            self.m_menu5 = wx.Menu()

                            self.m_menuItem8 = wx.MenuItem( self.m_menu5, wx.ID_ANY, u"Exportador", u"Exporta os arquivos da Base Local para Base Remota", wx.ITEM_NORMAL )

                            self.m_menu5.AppendItem( self.m_menuItem8 )

                           

                            self.m_menuItem9 = wx.MenuItem( self.m_menu5, wx.ID_ANY, u"Integrador App", u"Aguarda chegada de Pedidos do Aplicativo", wx.ITEM_NORMAL )

                            self.m_menu5.AppendItem( self.m_menuItem9 )

                           

                            self.m_menubar2.Append( self.m_menu5, u"Integrador" ) 

                           

                            self.m_menu12 = wx.Menu()

                            self.m_menuItem10 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Zerar Bonus Cliente", u"Zera bonus de cliente especifico", wx.ITEM_NORMAL )

                            self.m_menu12.AppendItem( self.m_menuItem10 )

                           

                            self.m_menuItem11 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Adicionar Bonus Cliente", u"Adiciona bonus para cliente especifico", wx.ITEM_NORMAL )

                            self.m_menu12.AppendItem( self.m_menuItem11 )

                           

                            self.m_menuItem12 = wx.MenuItem( self.m_menu12, wx.ID_ANY, u"Modificar Bonus Cliente", u"Modifica valor do bonus de cliente especifico", wx.ITEM_NORMAL )

                            self.m_menu12.AppendItem( self.m_menuItem12 )

                           

                            self.m_menubar2.Append( self.m_menu12, u"Manutencao" ) 

                           

                            self.m_config = wx.Menu()

                            self.m_menuItem3 = wx.MenuItem( self.m_config, wx.ID_ANY, u"Base de Dados", u"Configuração da Base de Dados", wx.ITEM_NORMAL )

                            self.m_config.AppendItem( self.m_menuItem3 )

                           

                            self.m_menuItem4 = wx.MenuItem( self.m_config, wx.ID_ANY, u"Horarios Funcionamento", u"Configura horário de funcionamento do Delivery", wx.ITEM_NORMAL )

                            self.m_config.AppendItem( self.m_menuItem4 )

                           

                            self.m_menuItem7 = wx.MenuItem( self.m_config, wx.ID_ANY, u"E-Mails de Segurança", u"Cadastra e-mails de seguranças para caso de \"emergência\"", wx.ITEM_NORMAL )

                            self.m_config.AppendItem( self.m_menuItem7 )

                           

                            self.m_menubar2.Append( self.m_config, u"Configurações" ) 

                           

                            self.m_menu2 = wx.Menu()

                            self.m_menubar2.Append( self.m_menu2, u"Sobre" ) 

                           

                            self.m_menu3 = wx.Menu()

                            self.m_menubar2.Append( self.m_menu3, u"Sair" ) 

                           

                            self.SetMenuBar( self.m_menubar2 )

                           

                            self.m_statusBar2 = self.CreateStatusBar( 1 )

                           

                            self.m_mgr.Update()

                            self.Centre( wx.BOTH )

                           

                            # Connect Events

                            self.Bind( wx.EVT_MENU, self.onMyFrame3, id = self.m_menuItem9.GetId() )

                           

             # Virtual event handlers, overide them in your derived class

             def onMyFrame3( self, event ):

                frame = SecondFrame()

                frame.Show()

 

            

             def __del__( self ):

                            self.m_mgr.UnInit()

 

app = wx.App(False)

frame = MyFrame2(None)

frame.Show(True)

app.MainLoop()

 

-------------------------------------------------------------------------------------

When I try to compile and run, python returns the following message:

Error: inconsistent indentation detected !

 

And shows this lines:

 

             def onMyFrame3( self, event ):

                frame = SecondFrame()

                frame.Show()

 

But if I try:

 

             def onMyFrame3( self, event ):

                event.Skip()

 

it doesnt return error... 

What i'm doing wrong ??

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Creating new form

Dionatan Moretti
Thanks!
It was exactly that!

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.