samedi 17 février 2018

tkinter if statement when I click no it displays yes

So I'm to all this coding stuff so I decided to mess around with tkinter to show my friends, but I've come across a problem in which at a certain point of the code, when I click no, it still displays what happens when you click yes instead. Here's the code I've written so far.

from tkinter import *
import tkinter.messagebox

root = Tk()

root.title("THE ULTIAMTE TEST OF STRENGTH")

root.geometry('375x50')

topframe = Frame(root)
topframe.pack(side=TOP)
bottomframe = Frame(root)
bottomframe.pack(side=BOTTOM)

def butt1(event):
tkinter.messagebox.showinfo("Narrator: WHAT HAVE YOU DONE", "Prepare your soul for the hardest question ever")

answer = tkinter.messagebox.askquestion("Mother:", "Just got back home from work. Have you cleaned your room?")

if answer == 'yes':
    tkinter.messagebox.showinfo("Mother:", "Wow, you actually did something useful for once.")

    tkinter.messagebox.askquestion("Mother:", "WAIT, have you done the dishes yet? ")

    if answer == 'yes':
        tkinter.messagebox.showinfo("Mother:", "I'm Surprised. You've never been this productive in your entire life. Good job.")
        tkinter.messagebox.askquestion("Mother:", "WAIT ANOTHER MINUTE YOU FRAGILE CHILD. Have you done your laundry? ")

        if answer == 'yes':
            tkinter.messagebox.showinfo("Mother:", "Oh my, what a miracle! I can't believe you actually did what you were supposed to do!")
            tkinter.messagebox.showinfo("Mother:", "I'm still gonna whoop ya")
            tkinter.messagebox.showinfo("Narrator:", "You got whooped.")

        if answer == 'no':
            tkinter.messagebox.showinfo("Mother:", "Oh my goodness you trashcan of a child, if you don't do yo laundry within the next 3 seconds I'm shoving all ya clothes down ya throat, YA HEAR ME?")

            tkinter.messagebox.showinfo("Narrator:", "It's been 3 seconds.")

    if answer == 'no':
        tkinter.messagebox.showinfo("Mother:", "Of course you haven't. There's only so much you can do before you become useless again.")

        tkinter.messagebox.askquestion("Mother:", "Last Question. Have you done your laundry?")

        if answer == 'yes':
            tkinter.messagebox.showinfo("Mother:", "Fair enough, but you still have to do the dishes or else you gettin'' the greatest whoopin of yo life.")

            tkinter.messagebox.showinfo("Narrator:", "Just do yo dang dishes")

        if answer == 'no':
            tkinter.messagebox.showinfo("Mother:", "Oh my goodness you trashcan of a child, if you don't do yo laundry within the next 3 seconds I'm shoving all ya clothes down ya throat, YA HEAR ME?")

            tkinter.messagebox.showinfo("Narrator:", "It's been 3 seconds.")


if answer == 'no':
    tkinter.messagebox.showinfo("Mother:", "YOU'RE SUCH A USELESS CHILD THERE'S NO POINT IN EVEN RAISING YOU AT THIS POINT")

    tkinter.messagebox.askquestion("Mother:", "Have you at least done the dishes?")

def butt2(event):
tkinter.messagebox.showinfo("WHAT HAVE YOU DONE", "Prepare your soul for the hardest question ever")

answer = tkinter.messagebox.askquestion("Mother:", "Just got back home from work. Have you cleaned your room?")

if answer == 'yes':
    tkinter.messagebox.showinfo("Mother:", "Wow, you actually did something useful for once.")

    tkinter.messagebox.askquestion("Mother:", "WAIT, have you done the dishes yet? ")

if answer == 'no':
    tkinter.messagebox.showinfo("Mother:", "YOU'RE SUCH A USELESS CHILD THERE'S NO POINT IN EVEN RAISING YOU AT THIS POINT")

    tkinter.messagebox.askquestion("Mother:", "Have you at least done the dishes?")

button_1 = Button(root, text="BEWARE OF THIS BUTTON", bg = 'black', fg='red')
button_1.bind("<Button-1>", butt1)
button_1.pack(fill=X)

button_2 = Button(root, text="DON'T BE AWARE OF THIS BUTTON", bg='yellow', fg='green')
button_2.bind("<Button-2>", butt2)
button_2.pack(fill=X)

button_1.pack(side=TOP)
button_2.pack(side=BOTTOM)
root.mainloop()

Also another thing is that when I click the second button, nothing happens at all. I hope what I said isn't too confusing

Aucun commentaire:

Enregistrer un commentaire