#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    12
    Rep Power
    0

    Open a window on button click event in wxPython


    Hi,
    can some one tell me how i must write a program to open a window on button click event.
    i have a login window and after i get the user name and password and when i click the login button i should be able to open the main window.can some tell me how i can do this using wxPython.

    thanks in advance.

    regards,
    suni16
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    Try something like this:
    • If you have not already done so, create a new dialog for user authentication
    • In the main application module there is a class BoaApp(wxApp) with a "OnInit" method. Insert a call to your authentication dialog just before the line "self.main.Show()"
    • If the identification succeeds, continue normally
    • If not, exit the OnInit method returning "False"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    10

    show and hide


    As suggested above

    You can create a window in the back ground
    and call Show(True) on it when you are ready to show it .

    or Call win.Show(False) when you want to hide it...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    12
    Rep Power
    0
    hi,
    i dont want to open a dialog i want to open a window.i have created a separate screen for login and main window . i want to know how to write the code to call the main window?.
    can u help me with an example.

    regards,
    suni16
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    If I got it right, you want the login window closed and another window opened if the "login" button is pressed. For this you need to add a button event to the login button (I assume you know how to do it.) In the event function, you can then do something like this:
    Code:
    # the main module contains the main window
    import main
    ...
    
    class Login(wxFrame):
        ...
    
        ...
        def OnLoginButton(self, event):
            # check if login is ok
            if self.login_ok()
                # create the main window
                win = main.create(self.GetParent())
                # show the main window
                win.Show()
            # close the login window
            self.Close()
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    12
    Rep Power
    0
    Hi,
    Thanks for ur help.i did exactly as to how u told me..

    from wxPython.wx import *
    import mainscreen

    wxID_Login = 100
    wxID_Cancel = 200
    wxID_Register = 300
    class LoginFrame(wxFrame):

    def __init__(self, parent, ID, title, pos, size):
    wxFrame.__init__(self, parent, ID, title, pos, size)

    panel = wxPanel(self, -1)

    # create the text and button widgets
    self.lLogin = wxStaticText(panel, -1, "Login :",(30,40))
    self.tUser = wxTextCtrl(panel, -1, "", (100,40),100,22))
    self.lPassword = wxStaticText(panel, -1, "Password :",(30,70))
    self.tPassword = wxTextCtrl(panel, -1, "", (100,70), (100,22))

    self.bSignin = wxButton(panel, wxID_Login, "Sign In", (20, 120),(50,30))
    self.bCancel = wxButton(panel, wxID_Cancel, "Cancel", (95, 120),(50,30))
    self.bRegister = wxButton(panel, wxID_Register, "Register", (170, 120),(50,30))

    self.tUser.SetFocus()

    EVT_BUTTON(self,wxID_Login, self.OnLogin)
    EVT_BUTTON(self, wxID_Cancel, self.OnCancel)
    EVT_BUTTON(self, 30, self.OnQuit)

    # these are our event handlers
    def OnLogin(self, event):
    if self.OnLogin:
    # create the main window
    win = mainscreen.Create(self.GetParent())
    # show the main window
    win.Show()
    # close the login window
    self.Close()


    but i'm getting an error :

    Traceback (most recent call last):
    File "C:\Documents and Settings\Administrator\Desktop\login.py", line 36, in OnLogin
    win = mainscreen.Create(self.GetParent())
    AttributeError: 'module' object has no attribute 'Create'

    can u tell me why i'm getting this error..

    regards,
    suni16
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    12
    Rep Power
    0

    Error in Create(self.GetParent())


    Hi,
    Thanks for ur help.i did exactly as to how u told me..

    from wxPython.wx import *
    import mainscreen

    wxID_Login = 100
    wxID_Cancel = 200
    wxID_Register = 300
    class LoginFrame(wxFrame):

    def __init__(self, parent, ID, title, pos, size):
    wxFrame.__init__(self, parent, ID, title, pos, size)

    panel = wxPanel(self, -1)

    # create the text and button widgets
    self.lLogin = wxStaticText(panel, -1, "Login :",(30,40))
    self.tUser = wxTextCtrl(panel, -1, "", (100,40),100,22))
    self.lPassword = wxStaticText(panel, -1, "Password :",(30,70))
    self.tPassword = wxTextCtrl(panel, -1, "", (100,70), (100,22))

    self.bSignin = wxButton(panel, wxID_Login, "Sign In", (20, 120),(50,30))
    self.bCancel = wxButton(panel, wxID_Cancel, "Cancel", (95, 120),(50,30))
    self.bRegister = wxButton(panel, wxID_Register, "Register", (170, 120),(50,30))

    self.tUser.SetFocus()

    EVT_BUTTON(self,wxID_Login, self.OnLogin)
    EVT_BUTTON(self, wxID_Cancel, self.OnCancel)

    # these are our event handlers
    def OnLogin(self, event):
    if self.OnLogin:
    # create the main window
    win = mainscreen.Create(self.GetParent())
    # show the main window
    win.Show()
    # close the login window
    self.Close()


    but i'm getting an error :

    Traceback (most recent call last):
    File "C:\Documents and Settings\Administrator\Desktop\login.py", line 36, in OnLogin
    win = mainscreen.Create(self.GetParent())
    AttributeError: 'module' object has no attribute 'Create'

    can u tell me why i'm getting this error..

    regards,
    suni16
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    Python names are case sensitive:
    Code:
    # "create" must be lowercase, see the code of your mainscreen module:
    win = mainscreen.create(self.GetParent())
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    12
    Rep Power
    0

    still same error


    hi ,

    i changed the case and again executed the program but i'm still getting the same errror.

    def OnLogin(self, event):
    if self.OnLogin:
    # create the main window
    win = mainscreen.create(self.GetParent())
    # show the main window
    win.Show()
    # close the login window
    self.Close()

    the error is still the same.
    Traceback (most recent call last):
    File "C:/Documents and Settings/Administrator/Desktop/login.py", line 31, in OnLogin
    win = mainscreen.create(self.GetParent())
    AttributeError: 'module' object has no attribute 'create'


    why am i getting this error?.should i import any other module.

    regards,
    suni16
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    Sorry, I think I was wrong because I assumed that you are using Boa Constructor as a GUI IDE, but apparently you don't. So you could either add a "create" function to the mainscreen module which returns a new window object, e.g.
    Code:
    def create(prnt):
        return MainWindow(id=..., name=..., parent=prnt,
                  pos=wxPoint(...), size=wxSize(...))
    or create the window object directly, e.g.:
    Code:
        win = mainscreen.MainWindow(id=..., name=..., parent=self.GetParent(),
                  pos=wxPoint(...), size=wxSize(...))
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    12
    Rep Power
    0

    Login window not closing


    Hi,
    I did the program using Boa Constructor and now i'm able to open the main window from the login window on button click.
    thanks u sir for u help.

    now i'm not able to close the login window after the mainwindow opens.i have tried self.Destroy() and self.Close().
    both dont seem to work.can u tell me what i should do now.

    regards,
    suni16

IMN logo majestic logo threadwatch logo seochat tools logo