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()









share|improve this question






















  • 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















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()









share|improve this question






















  • 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













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()









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python