Class object programming in Python [closed]










-1















import Tkinter
import random

class colourgame():

colours=['Red','Blue','Green','Pink','Black',
'Yellow','Orange','White','Purple','Brown']
score=0
timeleft=30

def __init__(self):
root = Tkinter.Tk()
root.title("COLORGAME")
root.geometry("375x200")
instructions = Tkinter.Label(root, text = "Type in the colour of the words, and not the word text!", font = ('Helvetica', 12))
instructions.pack()
scoreLabel = Tkinter.Label(root, text = "Press enter to start", font = ('Helvetica', 12))
scoreLabel.pack()
timeLabel = Tkinter.Label(root, text = "Time left: " +str(self.timeleft), font = ('Helvetica', 12))
timeLabel.pack()
label = Tkinter.Label(root, font = ('Helvetica', 60))
label.pack()
e = Tkinter.Entry(root)
root.bind('<Return>', self.startGame())
e.pack()
e.focus_set()
root.mainloop()

def startgame(self,event):

if self.timeleft==30:
self.countdown()
self.nextcolour()

def countdown(self):

if self.timeleft > 0:
self.timeleft -= 1
timeLabel.config(text = "Time left: "+ str(self.timeleft)) #explain
timeLabel.after(1000, self.countdown)

def nextColour(self):

if self.timeleft > 0:
e.focus_set()
if e.get().lower() == colours[1].lower():
self.score += 1
e.delete(0, Tkinter.END)
random.shuffle(colours)
label.config(fg = str(colours[1]), text = str(colours[0])) #explain
scoreLabel.config(text = "Score: " + str(self.score))


obj=colourgame()
obj.startGame()


The error that arises is:



AttributeError: colourgame instance has no attribute 'startGame'


Please someone explain me the reason.










share|improve this question















closed as off-topic by Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr Nov 13 '18 at 19:27


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • can you tell what line the error happens on

    – Brandalf
    Nov 13 '18 at 19:22















-1















import Tkinter
import random

class colourgame():

colours=['Red','Blue','Green','Pink','Black',
'Yellow','Orange','White','Purple','Brown']
score=0
timeleft=30

def __init__(self):
root = Tkinter.Tk()
root.title("COLORGAME")
root.geometry("375x200")
instructions = Tkinter.Label(root, text = "Type in the colour of the words, and not the word text!", font = ('Helvetica', 12))
instructions.pack()
scoreLabel = Tkinter.Label(root, text = "Press enter to start", font = ('Helvetica', 12))
scoreLabel.pack()
timeLabel = Tkinter.Label(root, text = "Time left: " +str(self.timeleft), font = ('Helvetica', 12))
timeLabel.pack()
label = Tkinter.Label(root, font = ('Helvetica', 60))
label.pack()
e = Tkinter.Entry(root)
root.bind('<Return>', self.startGame())
e.pack()
e.focus_set()
root.mainloop()

def startgame(self,event):

if self.timeleft==30:
self.countdown()
self.nextcolour()

def countdown(self):

if self.timeleft > 0:
self.timeleft -= 1
timeLabel.config(text = "Time left: "+ str(self.timeleft)) #explain
timeLabel.after(1000, self.countdown)

def nextColour(self):

if self.timeleft > 0:
e.focus_set()
if e.get().lower() == colours[1].lower():
self.score += 1
e.delete(0, Tkinter.END)
random.shuffle(colours)
label.config(fg = str(colours[1]), text = str(colours[0])) #explain
scoreLabel.config(text = "Score: " + str(self.score))


obj=colourgame()
obj.startGame()


The error that arises is:



AttributeError: colourgame instance has no attribute 'startGame'


Please someone explain me the reason.










share|improve this question















closed as off-topic by Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr Nov 13 '18 at 19:27


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • can you tell what line the error happens on

    – Brandalf
    Nov 13 '18 at 19:22













-1












-1








-1








import Tkinter
import random

class colourgame():

colours=['Red','Blue','Green','Pink','Black',
'Yellow','Orange','White','Purple','Brown']
score=0
timeleft=30

def __init__(self):
root = Tkinter.Tk()
root.title("COLORGAME")
root.geometry("375x200")
instructions = Tkinter.Label(root, text = "Type in the colour of the words, and not the word text!", font = ('Helvetica', 12))
instructions.pack()
scoreLabel = Tkinter.Label(root, text = "Press enter to start", font = ('Helvetica', 12))
scoreLabel.pack()
timeLabel = Tkinter.Label(root, text = "Time left: " +str(self.timeleft), font = ('Helvetica', 12))
timeLabel.pack()
label = Tkinter.Label(root, font = ('Helvetica', 60))
label.pack()
e = Tkinter.Entry(root)
root.bind('<Return>', self.startGame())
e.pack()
e.focus_set()
root.mainloop()

def startgame(self,event):

if self.timeleft==30:
self.countdown()
self.nextcolour()

def countdown(self):

if self.timeleft > 0:
self.timeleft -= 1
timeLabel.config(text = "Time left: "+ str(self.timeleft)) #explain
timeLabel.after(1000, self.countdown)

def nextColour(self):

if self.timeleft > 0:
e.focus_set()
if e.get().lower() == colours[1].lower():
self.score += 1
e.delete(0, Tkinter.END)
random.shuffle(colours)
label.config(fg = str(colours[1]), text = str(colours[0])) #explain
scoreLabel.config(text = "Score: " + str(self.score))


obj=colourgame()
obj.startGame()


The error that arises is:



AttributeError: colourgame instance has no attribute 'startGame'


Please someone explain me the reason.










share|improve this question
















import Tkinter
import random

class colourgame():

colours=['Red','Blue','Green','Pink','Black',
'Yellow','Orange','White','Purple','Brown']
score=0
timeleft=30

def __init__(self):
root = Tkinter.Tk()
root.title("COLORGAME")
root.geometry("375x200")
instructions = Tkinter.Label(root, text = "Type in the colour of the words, and not the word text!", font = ('Helvetica', 12))
instructions.pack()
scoreLabel = Tkinter.Label(root, text = "Press enter to start", font = ('Helvetica', 12))
scoreLabel.pack()
timeLabel = Tkinter.Label(root, text = "Time left: " +str(self.timeleft), font = ('Helvetica', 12))
timeLabel.pack()
label = Tkinter.Label(root, font = ('Helvetica', 60))
label.pack()
e = Tkinter.Entry(root)
root.bind('<Return>', self.startGame())
e.pack()
e.focus_set()
root.mainloop()

def startgame(self,event):

if self.timeleft==30:
self.countdown()
self.nextcolour()

def countdown(self):

if self.timeleft > 0:
self.timeleft -= 1
timeLabel.config(text = "Time left: "+ str(self.timeleft)) #explain
timeLabel.after(1000, self.countdown)

def nextColour(self):

if self.timeleft > 0:
e.focus_set()
if e.get().lower() == colours[1].lower():
self.score += 1
e.delete(0, Tkinter.END)
random.shuffle(colours)
label.config(fg = str(colours[1]), text = str(colours[0])) #explain
scoreLabel.config(text = "Score: " + str(self.score))


obj=colourgame()
obj.startGame()


The error that arises is:



AttributeError: colourgame instance has no attribute 'startGame'


Please someone explain me the reason.







python python-2.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 19:23









jwodder

33.1k35483




33.1k35483










asked Nov 13 '18 at 19:19









Susmita DuttaSusmita Dutta

61




61




closed as off-topic by Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr Nov 13 '18 at 19:27


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr Nov 13 '18 at 19:27


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Thomas, user2357112, juanpa.arrivillaga, zvone, mVChr
If this question can be reworded to fit the rules in the help center, please edit the question.












  • can you tell what line the error happens on

    – Brandalf
    Nov 13 '18 at 19:22

















  • can you tell what line the error happens on

    – Brandalf
    Nov 13 '18 at 19:22
















can you tell what line the error happens on

– Brandalf
Nov 13 '18 at 19:22





can you tell what line the error happens on

– Brandalf
Nov 13 '18 at 19:22












1 Answer
1






active

oldest

votes


















1














python is case sensitive. your issue is here:



obj=colourgame() 
obj.startGame() #this should be obj.startgame() because you defined it all lower case not CamelCase


you have the same issue in the __init__() definition in this line root.bind('<Return>', self.startGame()) which should be root.bind('<Return>', self.startgame())






share|improve this answer























  • Thank You so much for pointing out my mistake. It has worked.

    – Susmita Dutta
    Nov 13 '18 at 19:53

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














python is case sensitive. your issue is here:



obj=colourgame() 
obj.startGame() #this should be obj.startgame() because you defined it all lower case not CamelCase


you have the same issue in the __init__() definition in this line root.bind('<Return>', self.startGame()) which should be root.bind('<Return>', self.startgame())






share|improve this answer























  • Thank You so much for pointing out my mistake. It has worked.

    – Susmita Dutta
    Nov 13 '18 at 19:53















1














python is case sensitive. your issue is here:



obj=colourgame() 
obj.startGame() #this should be obj.startgame() because you defined it all lower case not CamelCase


you have the same issue in the __init__() definition in this line root.bind('<Return>', self.startGame()) which should be root.bind('<Return>', self.startgame())






share|improve this answer























  • Thank You so much for pointing out my mistake. It has worked.

    – Susmita Dutta
    Nov 13 '18 at 19:53













1












1








1







python is case sensitive. your issue is here:



obj=colourgame() 
obj.startGame() #this should be obj.startgame() because you defined it all lower case not CamelCase


you have the same issue in the __init__() definition in this line root.bind('<Return>', self.startGame()) which should be root.bind('<Return>', self.startgame())






share|improve this answer













python is case sensitive. your issue is here:



obj=colourgame() 
obj.startGame() #this should be obj.startgame() because you defined it all lower case not CamelCase


you have the same issue in the __init__() definition in this line root.bind('<Return>', self.startGame()) which should be root.bind('<Return>', self.startgame())







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 19:22









vencaslacvencaslac

1,002217




1,002217












  • Thank You so much for pointing out my mistake. It has worked.

    – Susmita Dutta
    Nov 13 '18 at 19:53

















  • Thank You so much for pointing out my mistake. It has worked.

    – Susmita Dutta
    Nov 13 '18 at 19:53
















Thank You so much for pointing out my mistake. It has worked.

– Susmita Dutta
Nov 13 '18 at 19:53





Thank You so much for pointing out my mistake. It has worked.

– Susmita Dutta
Nov 13 '18 at 19:53



這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto