Class object programming in Python [closed]
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
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
add a comment |
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
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
can you tell what line the error happens on
– Brandalf
Nov 13 '18 at 19:22
add a comment |
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
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
python python-2.7
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
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
can you tell what line the error happens on
– Brandalf
Nov 13 '18 at 19:22
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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())
Thank You so much for pointing out my mistake. It has worked.
– Susmita Dutta
Nov 13 '18 at 19:53
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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())
Thank You so much for pointing out my mistake. It has worked.
– Susmita Dutta
Nov 13 '18 at 19:53
add a comment |
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())
Thank You so much for pointing out my mistake. It has worked.
– Susmita Dutta
Nov 13 '18 at 19:53
add a comment |
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())
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())
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
add a comment |
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
add a comment |
can you tell what line the error happens on
– Brandalf
Nov 13 '18 at 19:22