Reputation: 451
I'am a new bie in python,I have to call a frame "Frame2" when I clic on a button from Frame1,I have this error:
this I my code:
global Frame2 fr
def OnButton4Button(self, event):
fr.Show()
even.Skip()
NB:I work with wxpython,and boa constructor thanks fro help
Upvotes: 0
Views: 101
Reputation: 15328
In your short code you have an indentation on the second line, this is an error, you must write it like:
from Frame2 import fr
def OnButton4Button(self, event):
fr.Show()
event.Skip()
You may respect the indentation in Python like following example:
global var
def function():
#indented block
#should be always on the same column
condition = 1
if condition:
#new indented block
#is also aligned on a column
print "something"
#this is out of the IF block
#call the function
function()
In the PEP8 recommendations you will find the rules to avoid indenting errors.
Upvotes: 1
Reputation: 33111
You have several typos in your code. Here's a corrected example:
from Frame2 import fr
def OnButton4Button(self, event):
fr.Show()
event.Skip() # you need to spell event correctly
This assumes that Frame2 is a module. Most of the time, you don't need to use globals in Python.
To make this a bit easier to follow, I wrote an example that has a MainFrame class and a Frame2 class in the same module so you don't have to import anything or use globals:
import wx
########################################################################
class Frame2(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Frame2")
panel = wx.Panel(self)
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Main Frame")
panel = wx.Panel(self)
button = wx.Button(panel, label="Open Frame2")
button.Bind(wx.EVT_BUTTON, self.onButton)
self.Show()
#----------------------------------------------------------------------
def onButton(self, event):
""""""
frame = Frame2()
frame.Show()
event.Skip()
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
Upvotes: 1