The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
"GraphWin Object is not callable"
Discuss "GraphWin Object is not callable" in the Python Programming forum on Dev Shed. "GraphWin Object is not callable" Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 30th, 2012, 05:54 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 18
Time spent in forums: 14 h 30 m 46 sec
Reputation 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?
|

November 30th, 2012, 06:49 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Time spent in forums: 1 h 5 m 41 sec
Reputation 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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|