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

    Join Date
    Nov 2012
    Posts
    18
    Rep Power
    0

    "GraphWin Object is not callable"


    When I a section of code into a new function, it comes up with "GraphWin Object is not callable"

    This is my whole code

    Code:
    from graphics import *
    import urllib.request, re
    
    def LoginScreen():
        LoginScreen = GraphWin("Login",300,100)
        file = open("users.csv","r")
        readfile = file.read()
        UsernameLabel = Text(Point(45,25),"Username: ")
        UsernameLabel.draw(LoginScreen)
        UsernameText = Entry(Point(158,25),16)
        UsernameText.draw(LoginScreen)
        username = ''
        LoginScreen.getMouse()
        LoginScreen.close()
    
    def RegisterScreen():
        RegisterScreen = GraphWin("Register",300,150)
        UsernameRegLabel = Text(Point(45,25),"Username: ")
        UsernameRegLabel.draw(RegisterScreen)
        UsernameRegText = Entry(Point(175,25),20)
        UsernameRegText.draw(RegisterScreen)
        PasswordRegLabel = Text(Point(45,50),"Password: ")
        PasswordRegLabel.draw(RegisterScreen)
        PasswordRegText = Entry(Point(175,50),20)
        PasswordRegText.draw(RegisterScreen)
        PasswordConfRegLabel = Text(Point(52,75),"Confirm: ")
        PasswordConfRegLabel.draw(RegisterScreen)
        PasswordConfRegText = Entry(Point(175,75),20)
        PasswordConfRegText.draw(RegisterScreen)
        EmailRegLabel = Text(Point(60,100),"Email: ")
        EmailRegLabel.draw(RegisterScreen)
        EmailRegText = Entry(Point(175,100),20)
        EmailRegText.draw(RegisterScreen)
        SubmitButton = Rectangle(Point(195,115),Point(265,140))
        SubmitButton.draw(RegisterScreen)
        SubmitButtonText = Text(Point(230,128),"Submit")
        SubmitButtonText.draw(RegisterScreen)
        CloseButton = Rectangle(Point(115,115),Point(185,140))
        CloseButton.draw(RegisterScreen)
        CloseButtonText = Text(Point(150,128),"Close")
        CloseButtonText.draw(RegisterScreen)
    
    def GetMouseRegistration():
        MouseRegScreen = RegisterScreen.getMouse()
        RegScreenX = MouseRegScreen.getX()
        RegScreenY = MouseRegScreen.getY()
    
        if RegScreenX>=195 and RegScreenX<=265:
            if RegScreenY>=115 and RegScreenY<=140:
                ProcessRegister()
        elif RegScreenX>=115 and RegScreenX<=185:
            if RegScreenY>=115 and RegScreenY<=140:
                RegisterScreen.close()
    
    def ValidateRegistration():
        return
    
    def ProcessRegister():
        ValidateRegistration()
    
    def GetMouse():
        MouseMainScreen = MainWin.getMouse()
        MainScreenX = MouseMainScreen.getX()
        MainScreenY = MouseMainScreen.getY()
        
        if MainScreenX>=197 and MainScreenX<=260:
            if MainScreenY>=230 and MainScreenY<=250:
                LoginScreen()
        if MainScreenX>=197 and MainScreenX<=297:
            if MainScreenY>=260 and MainScreenY<=285:
                RegisterScreen()
        
    def DrawBackground():
        return
        
    def DrawMenuItems():
        Main = Text(Point(300,200),"Main Menu")
        Main.setSize(32)
        Main.draw(MainWin)
        Login = Text(Point(228,240),"Login")
        Login.setSize(20)
        Login.draw(MainWin)
        Register = Text(Point(245,270),"Register")
        Register.setSize(20)
        Register.draw(MainWin)
    
    MainWin = GraphWin("Fantasy Football",600,600)
    
    DrawBackground()
    DrawMenuItems()
    while True:
        GetMouse()
    This is the original code that I'm changing

    Code:
    def RegisterScreen():
        RegisterScreen = GraphWin("Register",300,150)
        UsernameRegLabel = Text(Point(45,25),"Username: ")
        UsernameRegLabel.draw(RegisterScreen)
        UsernameRegText = Entry(Point(175,25),20)
        UsernameRegText.draw(RegisterScreen)
        PasswordRegLabel = Text(Point(45,50),"Password: ")
        PasswordRegLabel.draw(RegisterScreen)
        PasswordRegText = Entry(Point(175,50),20)
        PasswordRegText.draw(RegisterScreen)
        PasswordConfRegLabel = Text(Point(52,75),"Confirm: ")
        PasswordConfRegLabel.draw(RegisterScreen)
        PasswordConfRegText = Entry(Point(175,75),20)
        PasswordConfRegText.draw(RegisterScreen)
        EmailRegLabel = Text(Point(60,100),"Email: ")
        EmailRegLabel.draw(RegisterScreen)
        EmailRegText = Entry(Point(175,100),20)
        EmailRegText.draw(RegisterScreen)
        SubmitButton = Rectangle(Point(195,115),Point(265,140))
        SubmitButton.draw(RegisterScreen)
        SubmitButtonText = Text(Point(230,128),"Submit")
        SubmitButtonText.draw(RegisterScreen)
        CloseButton = Rectangle(Point(115,115),Point(185,140))
        CloseButton.draw(RegisterScreen)
        CloseButtonText = Text(Point(150,128),"Close")
        CloseButtonText.draw(RegisterScreen)
    
        MouseRegScreen = RegisterScreen.getMouse()
        RegScreenX = MouseRegScreen.getX()
        RegScreenY = MouseRegScreen.getY()
    
        if RegScreenX>=195 and RegScreenX<=265:
            if RegScreenY>=115 and RegScreenY<=140:
                ProcessRegister()
        elif RegScreenX>=115 and RegScreenX<=185:
            if RegScreenY>=115 and RegScreenY<=140:
                RegisterScreen.close()
    The last section I want to take out and put in another function like this.

    Code:
    def GetMouseRegistration():
        MouseRegScreen = RegisterScreen.getMouse()
        RegScreenX = MouseRegScreen.getX()
        RegScreenY = MouseRegScreen.getY()
    
        if RegScreenX>=195 and RegScreenX<=265:
            if RegScreenY>=115 and RegScreenY<=140:
                ProcessRegister()
        elif RegScreenX>=115 and RegScreenX<=185:
            if RegScreenY>=115 and RegScreenY<=140:
                RegisterScreen.close()
    I've tried making the RegisterScreen Window a global variable, but that's when it says it isn't callable.

    I'm also having a problem when the user clicks on the x in the top right corner to close it, is there any way to stop the error from crashing the program?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    You should use inheritance to create two classes(LoginScreenC, RegisterScreenC) that are derived from GraphWin, in these classes you can overwrite the GetMouse function.
    Then you can create:

    MainWin = LoginScreenC("Fantasy Football",600,600)

    and in your RegisterScreen() function change:

    RegisterScreen = RegisterScreenC("Register",300,150)

    and append to the end of this function:

    RegisterScreen.getMouse()
    RegisterScreen.close()

    Obviously you have to overwrite the getMouse functions in the two classes to fit your buttonsizes and needs

    But why do you want to put this in a extra function anyway, this seems to work just fine:

    Code:
    def RegisterScreen():
        RegisterScreen = GraphWin("Register",300,150)
        UsernameRegLabel = Text(Point(45,25),"Username: ")
        UsernameRegLabel.draw(RegisterScreen)
        UsernameRegText = Entry(Point(175,25),20)
        UsernameRegText.draw(RegisterScreen)
        PasswordRegLabel = Text(Point(45,50),"Password: ")
        PasswordRegLabel.draw(RegisterScreen)
        PasswordRegText = Entry(Point(175,50),20)
        PasswordRegText.draw(RegisterScreen)
        PasswordConfRegLabel = Text(Point(52,75),"Confirm: ")
        PasswordConfRegLabel.draw(RegisterScreen)
        PasswordConfRegText = Entry(Point(175,75),20)
        PasswordConfRegText.draw(RegisterScreen)
        EmailRegLabel = Text(Point(60,100),"Email: ")
        EmailRegLabel.draw(RegisterScreen)
        EmailRegText = Entry(Point(175,100),20)
        EmailRegText.draw(RegisterScreen)
        SubmitButton = Rectangle(Point(195,115),Point(265,140))
        SubmitButton.draw(RegisterScreen)
        SubmitButtonText = Text(Point(230,128),"Submit")
        SubmitButtonText.draw(RegisterScreen)
        CloseButton = Rectangle(Point(115,115),Point(185,140))
        CloseButton.draw(RegisterScreen)
        CloseButtonText = Text(Point(150,128),"Close")
        CloseButtonText.draw(RegisterScreen)
        MouseRegScreen = RegisterScreen.getMouse()
        RegScreenX = MouseRegScreen.getX()
        RegScreenY = MouseRegScreen.getY()
    
        if RegScreenX>=195 and RegScreenX<=265:
            if RegScreenY>=115 and RegScreenY<=140:
                ProcessRegister()
        elif RegScreenX>=115 and RegScreenX<=185:
            if RegScreenY>=115 and RegScreenY<=140:
                RegisterScreen.close()
    Regards,
    Marcurion

IMN logo majestic logo threadwatch logo seochat tools logo