Checking Whether Class Var Happens
up vote
0
down vote
favorite
So i'm trying to make this simple multiple choice quiz and i want to make it object oriented. I've created the class in which a question can be modeled around but i want when the first question is answered
i wan the second question to start but i have tried a class var changes but nothing works
My Code:
import tkinter
from tkinter import *
root = Tk()
canvas = Canvas(root, width=500, height=500)
canvas.pack()
class Window:
def __init__(self, root, canvas, question, a, b, c, correct):
self.root = root
self.canvas = canvas
self.question = question
self.answerA = a
self.answerB = b
self.answerC = c
self.answer = correct
self.final = False
if self.answer == 1:
self.canvas.tag_bind('A', '<Button 1>', self.correct)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 2:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.correct)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 3:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.correct)
self.canvas.tag_bind('Again', '<Button 1>', self.redirect)
self.canvas.tag_bind('Correct', '<Button 1>', self.redirect)
def draw(self):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text=self.question, font=('Helvetica', 20))
self.canvas.create_rectangle(100, 250, 150, 300, fill='Black', activefill='Orange', tags='A')
self.canvas.create_rectangle(225, 250, 275, 300, fill='Black', activefill='Orange', tags='B')
self.canvas.create_rectangle(350, 250, 400, 300, fill='Black', activefill='Orange', tags='C')
self.canvas.create_text(125, 350, text=self.answerA, font=('Helvetica', 15), width=100)
self.canvas.create_text(250, 350, text=self.answerB, font=('Helvetica', 15), width=100)
self.canvas.create_text(375, 350, text=self.answerC, font=('Helvetica', 15), width=100)
def correct(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Correct', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Correct')
self.right = True
self.wrongg = False
def wrong(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Wrong', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Again')
self.wrongg = True
self.right = False
def redirect(self, event):
print('Redirecting...')
if self.wrongg == True:
print('Drawing...')
self.draw()
elif self.correct == True:
self.final = True
questionOne = Window(root, canvas, 'test', 'a', 'b', 'c', 3)
questionOne.draw()
root.mainloop()
python python-3.x oop tkinter
add a comment |
up vote
0
down vote
favorite
So i'm trying to make this simple multiple choice quiz and i want to make it object oriented. I've created the class in which a question can be modeled around but i want when the first question is answered
i wan the second question to start but i have tried a class var changes but nothing works
My Code:
import tkinter
from tkinter import *
root = Tk()
canvas = Canvas(root, width=500, height=500)
canvas.pack()
class Window:
def __init__(self, root, canvas, question, a, b, c, correct):
self.root = root
self.canvas = canvas
self.question = question
self.answerA = a
self.answerB = b
self.answerC = c
self.answer = correct
self.final = False
if self.answer == 1:
self.canvas.tag_bind('A', '<Button 1>', self.correct)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 2:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.correct)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 3:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.correct)
self.canvas.tag_bind('Again', '<Button 1>', self.redirect)
self.canvas.tag_bind('Correct', '<Button 1>', self.redirect)
def draw(self):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text=self.question, font=('Helvetica', 20))
self.canvas.create_rectangle(100, 250, 150, 300, fill='Black', activefill='Orange', tags='A')
self.canvas.create_rectangle(225, 250, 275, 300, fill='Black', activefill='Orange', tags='B')
self.canvas.create_rectangle(350, 250, 400, 300, fill='Black', activefill='Orange', tags='C')
self.canvas.create_text(125, 350, text=self.answerA, font=('Helvetica', 15), width=100)
self.canvas.create_text(250, 350, text=self.answerB, font=('Helvetica', 15), width=100)
self.canvas.create_text(375, 350, text=self.answerC, font=('Helvetica', 15), width=100)
def correct(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Correct', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Correct')
self.right = True
self.wrongg = False
def wrong(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Wrong', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Again')
self.wrongg = True
self.right = False
def redirect(self, event):
print('Redirecting...')
if self.wrongg == True:
print('Drawing...')
self.draw()
elif self.correct == True:
self.final = True
questionOne = Window(root, canvas, 'test', 'a', 'b', 'c', 3)
questionOne.draw()
root.mainloop()
python python-3.x oop tkinter
Can you please explain what it means: "Nothing works"? Do you receive an error message? Does something work? Have you tried unit testing? So, did you try to test the code step-by-step?
– Alex_P
Nov 11 at 17:12
@Alex_P By nothing works i mean ive tried different methods like returning values from the class then doing an if statement but even though the values change in the class the if statement doesnt work beacuse theres no loop, this could work but i dont know if theres a better way about it. Thats why theres a self.final so if you get it correct it will be true if its true then go to next question
– Charlie MORTIMER
Nov 11 at 19:56
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So i'm trying to make this simple multiple choice quiz and i want to make it object oriented. I've created the class in which a question can be modeled around but i want when the first question is answered
i wan the second question to start but i have tried a class var changes but nothing works
My Code:
import tkinter
from tkinter import *
root = Tk()
canvas = Canvas(root, width=500, height=500)
canvas.pack()
class Window:
def __init__(self, root, canvas, question, a, b, c, correct):
self.root = root
self.canvas = canvas
self.question = question
self.answerA = a
self.answerB = b
self.answerC = c
self.answer = correct
self.final = False
if self.answer == 1:
self.canvas.tag_bind('A', '<Button 1>', self.correct)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 2:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.correct)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 3:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.correct)
self.canvas.tag_bind('Again', '<Button 1>', self.redirect)
self.canvas.tag_bind('Correct', '<Button 1>', self.redirect)
def draw(self):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text=self.question, font=('Helvetica', 20))
self.canvas.create_rectangle(100, 250, 150, 300, fill='Black', activefill='Orange', tags='A')
self.canvas.create_rectangle(225, 250, 275, 300, fill='Black', activefill='Orange', tags='B')
self.canvas.create_rectangle(350, 250, 400, 300, fill='Black', activefill='Orange', tags='C')
self.canvas.create_text(125, 350, text=self.answerA, font=('Helvetica', 15), width=100)
self.canvas.create_text(250, 350, text=self.answerB, font=('Helvetica', 15), width=100)
self.canvas.create_text(375, 350, text=self.answerC, font=('Helvetica', 15), width=100)
def correct(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Correct', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Correct')
self.right = True
self.wrongg = False
def wrong(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Wrong', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Again')
self.wrongg = True
self.right = False
def redirect(self, event):
print('Redirecting...')
if self.wrongg == True:
print('Drawing...')
self.draw()
elif self.correct == True:
self.final = True
questionOne = Window(root, canvas, 'test', 'a', 'b', 'c', 3)
questionOne.draw()
root.mainloop()
python python-3.x oop tkinter
So i'm trying to make this simple multiple choice quiz and i want to make it object oriented. I've created the class in which a question can be modeled around but i want when the first question is answered
i wan the second question to start but i have tried a class var changes but nothing works
My Code:
import tkinter
from tkinter import *
root = Tk()
canvas = Canvas(root, width=500, height=500)
canvas.pack()
class Window:
def __init__(self, root, canvas, question, a, b, c, correct):
self.root = root
self.canvas = canvas
self.question = question
self.answerA = a
self.answerB = b
self.answerC = c
self.answer = correct
self.final = False
if self.answer == 1:
self.canvas.tag_bind('A', '<Button 1>', self.correct)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 2:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.correct)
self.canvas.tag_bind('C', '<Button 1>', self.wrong)
elif self.answer == 3:
self.canvas.tag_bind('A', '<Button 1>', self.wrong)
self.canvas.tag_bind('B', '<Button 1>', self.wrong)
self.canvas.tag_bind('C', '<Button 1>', self.correct)
self.canvas.tag_bind('Again', '<Button 1>', self.redirect)
self.canvas.tag_bind('Correct', '<Button 1>', self.redirect)
def draw(self):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text=self.question, font=('Helvetica', 20))
self.canvas.create_rectangle(100, 250, 150, 300, fill='Black', activefill='Orange', tags='A')
self.canvas.create_rectangle(225, 250, 275, 300, fill='Black', activefill='Orange', tags='B')
self.canvas.create_rectangle(350, 250, 400, 300, fill='Black', activefill='Orange', tags='C')
self.canvas.create_text(125, 350, text=self.answerA, font=('Helvetica', 15), width=100)
self.canvas.create_text(250, 350, text=self.answerB, font=('Helvetica', 15), width=100)
self.canvas.create_text(375, 350, text=self.answerC, font=('Helvetica', 15), width=100)
def correct(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Correct', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Correct')
self.right = True
self.wrongg = False
def wrong(self, event):
self.canvas.delete(ALL)
self.canvas.create_text(250, 125, text='Wrong', font=('Helvetica', 20))
self.canvas.create_rectangle(125, 250, 375, 400, fill='Black', activefill='Orange', tags='Again')
self.wrongg = True
self.right = False
def redirect(self, event):
print('Redirecting...')
if self.wrongg == True:
print('Drawing...')
self.draw()
elif self.correct == True:
self.final = True
questionOne = Window(root, canvas, 'test', 'a', 'b', 'c', 3)
questionOne.draw()
root.mainloop()
python python-3.x oop tkinter
python python-3.x oop tkinter
asked Nov 11 at 16:39
Charlie MORTIMER
1
1
Can you please explain what it means: "Nothing works"? Do you receive an error message? Does something work? Have you tried unit testing? So, did you try to test the code step-by-step?
– Alex_P
Nov 11 at 17:12
@Alex_P By nothing works i mean ive tried different methods like returning values from the class then doing an if statement but even though the values change in the class the if statement doesnt work beacuse theres no loop, this could work but i dont know if theres a better way about it. Thats why theres a self.final so if you get it correct it will be true if its true then go to next question
– Charlie MORTIMER
Nov 11 at 19:56
add a comment |
Can you please explain what it means: "Nothing works"? Do you receive an error message? Does something work? Have you tried unit testing? So, did you try to test the code step-by-step?
– Alex_P
Nov 11 at 17:12
@Alex_P By nothing works i mean ive tried different methods like returning values from the class then doing an if statement but even though the values change in the class the if statement doesnt work beacuse theres no loop, this could work but i dont know if theres a better way about it. Thats why theres a self.final so if you get it correct it will be true if its true then go to next question
– Charlie MORTIMER
Nov 11 at 19:56
Can you please explain what it means: "Nothing works"? Do you receive an error message? Does something work? Have you tried unit testing? So, did you try to test the code step-by-step?
– Alex_P
Nov 11 at 17:12
Can you please explain what it means: "Nothing works"? Do you receive an error message? Does something work? Have you tried unit testing? So, did you try to test the code step-by-step?
– Alex_P
Nov 11 at 17:12
@Alex_P By nothing works i mean ive tried different methods like returning values from the class then doing an if statement but even though the values change in the class the if statement doesnt work beacuse theres no loop, this could work but i dont know if theres a better way about it. Thats why theres a self.final so if you get it correct it will be true if its true then go to next question
– Charlie MORTIMER
Nov 11 at 19:56
@Alex_P By nothing works i mean ive tried different methods like returning values from the class then doing an if statement but even though the values change in the class the if statement doesnt work beacuse theres no loop, this could work but i dont know if theres a better way about it. Thats why theres a self.final so if you get it correct it will be true if its true then go to next question
– Charlie MORTIMER
Nov 11 at 19:56
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250880%2fchecking-whether-class-var-happens%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please explain what it means: "Nothing works"? Do you receive an error message? Does something work? Have you tried unit testing? So, did you try to test the code step-by-step?
– Alex_P
Nov 11 at 17:12
@Alex_P By nothing works i mean ive tried different methods like returning values from the class then doing an if statement but even though the values change in the class the if statement doesnt work beacuse theres no loop, this could work but i dont know if theres a better way about it. Thats why theres a self.final so if you get it correct it will be true if its true then go to next question
– Charlie MORTIMER
Nov 11 at 19:56