خرید بک لینک

Vote count: 0

So Ive been working to make a Mad Libs program One button says next and the other back. Next stores the inputs as variables and changes the label. Back goes to the previous labels. After its done a messagebox pops up and says the paragraph with the variables. If only Next is pressed its fine. When Back is pressed its fine. But when Back then Next is pressed next just stops working. One solution I thought was doing

root.update()

But that was unsucessful.

from tkinter import *
from tkinter import messagebox

root = Tk()
root.title("Mad Libs: Action Movie")

x = 0



#para is the paragraph %s is variable
Para = '''%s is a normal %s. Then, one day, a %s explodes, causing a %s to blow up, and a nearby %s erupts into a %s of flames.%s realizes that he's being chased by the govement, who's trying to %s him. While on the run, he teams up with an incredibly attractive woman named %s, who has an incredible %s. She may be from the streets, but she can %s like nobody's buisness. The duo decide to tu tables on their pursuers by blowing up a %s, which triggers a chain reaction, causing the local %s, %s, and %s to explode. Then, the bad guys' helicopter gets %s by a piece of %s from when the %s exploded, and the helicopter explodes and falls onto a %s, causing it to %s, which shoots a fireball straight into the heart of %s and destroys the bad guy leader. Everything is %s and the two decide that such a %s ordeal has caused them to fall in %s with each other. They decide to celebrate by %s on the %s,and they even managed to use a %s from the begiing of the movie, to %s the whole story together.'''

l1 = Label(root, text="Man's Name")
l1.pack(side='top', fill='none', expand=False, padx=0, pady=4)#padx and pady change button location

e1 = Entry(root)
e1.pack(side='top', fill='none', expand=False, padx=1, pady=4)#labels and entry boxs

l2 = Label(root, text="Occupation")
l2.pack(side='top', fill='none', expand=False, padx=4, pady=4)

e2 = Entry(root)
e2.pack(side='top', fill='none', expand=False, padx=5, pady=4)

l3 = Label(root, text="Noun")
l3.pack(side='top', fill='none', expand=False, padx=8, pady=4)

e3 = Entry(root)
e3.pack(side='top', fill='none', expand=False, padx=9, pady=4)


l4 = Label(root, text="Noun")
l4.pack(side='top', fill='none', expand=False, padx=12, pady=4)

e4 = Entry(root)
e4.pack(side='top', fill='none', expand=False, padx=13, pady=4)

l5 = Label(root, text="Noun")
l5.pack(side='top', fill='none', expand=False, padx=16, pady=4)

e5 = Entry(root)
e5.pack(side='top', fill='none', expand=False, padx=17, pady=4)

l6 = Label(root, text="Shape")
l6.pack(side='top', fill='none', expand=False, padx=20, pady=4)

e6 = Entry(root)
e6.pack(side='top', fill='none', expand=False, padx=21, pady=4)

l7 = Label(root, text="Man's Name")
l7.pack(side='top', fill='none', expand=False, padx=24, pady=8)

e7 = Entry(root)
e7.pack(side='top', fill='none', expand=False, padx=25, pady=4)

root.geometry('500x500')


LN = Label(root, text="1 of 4")
LN.pack(side='bottom', fill='none', expand=False, padx=20, pady=4)

MN1 = ' '#defining variables
O1 = ' '
N1 = ' '
N2 = ' '
N3 = ' '
S1 = ' '
MN2 = ' '
V1 = ' '
WN1 = ' '
BP1 = ' '
V2 = ' '
N4 = ' '
N5 = ' '
RN1 = ' '
HM1 = ' '
V3 = ' '
N6 = ' '
N7 = ' '
N8 = ' '
V4 = ' '
N9 = ' '
A1 = ' '
A2 = ' '
E1 = ' '
V5 = ' '
N10 = ' '
N11 = ' '
V6 = ' '


def Next():
    global x
    global MN1
    global O1 
    global N1
    global N2
    global N3
    global S1
    global MN2
    global V1
    global WN1
    global BP1
    global V2
    global N4
    global N5
    global RN1
    global HM1
    global V3
    global N6
    global N7
    global N8
    global V4
    global N9
    global A1
    global A2
    global E1
    global V5
    global N10
    global N11
    global V6

    x = x

    if x == 0:
        l1["text"]="Verb"#7 changes text
        l2["text"]="Woman's Name"#8
        l3["text"]="Body Part"#9
        l4["text"]="Verb"#10
        l5["text"]="Noun"#11
        l6["text"]="Noun"#12
        l7["text"]="Restaurant Name"#13
        MN1 = e1.get()#saves previous variable
        O1 = e2.get()
        N1 = e3.get()
        N2 = e4.get()
        N3 = e5.get()
        S1 = e6.get()
        MN2 = e7.get()
        LN["text"]="2 of 4"

    elif x == 1:
        l1["text"]="Historic Monument"#14
        l2["text"]="Verb Ending In ED"#15
        l3["text"]="Noun"#16
        l4["text"]="Noun"#17
        l5["text"]="Noun"#18
        l6["text"]="Verb"#19
        l7["text"]="Noun"#20
        V1 = e1.get()
        WN1 = e2.get()
        BP1 = e3.get()
        V2 = e4.get()
        N4 = e5.get()
        N5 = e6.get()
        RN1 = e7.get()
        LN["text"]="3 of 4"

    else:
        l1["text"]="Adjective"#21
        l2["text"]="Adjective"#22
        l3["text"]="Emotion"#23
        l4["text"]="Verb Ending In Ing"#24
        l5["text"]="Noun"#25
        l6["text"]="Noun"#26
        l7["text"]="Verb"#27    
        HM1 = e1.get()
        V3 = e2.get()
        N6 = e3.get()
        N7 = e4.get()
        N8 = e5.get()
        V4 = e6.get()
        N9 = e7.get()
        LN["text"]="4 of 4"
        Next.configure(text='Submit', command=Submit)# changes next to make it Submit when at end







    root.update()
    e1.delete(0, END)#clears input
    e2.delete(0, END)
    e3.delete(0, END)
    e4.delete(0, END)
    e5.delete(0, END)
    e6.delete(0, END)
    e7.delete(0, END)

    if x <= 3:#stops variable from increasing tooo far
        x = x+1

x = x#restates x as the value that next has increased it to

def Back():
    global x
    global MN1
    global O1 
    global N1
    global N2
    global N3
    global S1
    global MN2
    global V1
    global WN1
    global BP1
    global V2
    global N4
    global N5
    global RN1
    global HM1
    global V3
    global N6
    global N7
    global N8
    global V4
    global N9
    global A1
    global A2
    global E1
    global V5
    global N10
    global N11
    global V6

    x = x



    if x == 1:
        l1["text"]="Man's Name"#7 changes text only since variables will be changed by next
        l2["text"]="Occupation"#8
        l3["text"]="Noun"#9
        l4["text"]="Noun"#10
        l5["text"]="Noun"#11
        l6["text"]="Shape"#12
        l7["text"]="Man's Name"#13

    elif x == 2:
        l1["text"]="Verb"#7
        l2["text"]="Woman's Name"#8
        l3["text"]="Body Part"#9
        l4["text"]="Verb"#10
        l5["text"]="Noun"#11
        l6["text"]="Noun"#12
        l7["text"]="Restaurant Name"#13

    elif x == 3:
        l1["text"]="Historic Monument"#14
        l2["text"]="Verb Ending In ED"#15
        l3["text"]="Noun"#16
        l4["text"]="Noun"#17
        l5["text"]="Noun"#18
        l6["text"]="Verb"#19
        l7["text"]="Noun"#20

    else:
        l1["text"]="Adjective"#21
        l2["text"]="Adjective"#22
        l3["text"]="Emotion"#23
        l4["text"]="Verb Ending In Ing"#24
        l5["text"]="Noun"#25
        l6["text"]="Noun"#26
        l7["text"]="Verb"#27
    root.update()
    Next.configure(text='Next', command=Next)# just in case Next is Submit

    if x >= 1:# stops back from going toooo low
        x = x-1

    e1.delete(0, END)
    e2.delete(0, END)
    e3.delete(0, END)
    e4.delete(0, END)
    e5.delete(0, END)
    e6.delete(0, END)
    e7.delete(0, END)



def Submit():
    global Para
    global A1
    global A2
    global E1
    global V5
    global N10
    global N11
    global V6

    x = x
    A1 = e1.get()#gets final variables
    A2 = e2.get()
    E1 = e3.get()
    V5 = e4.get()
    N10 = e5.get()
    N11 = e6.get()
    V6 = e7.get() 
    #takes Para and fills in %s with variables chronologicaly
    messagebox.showinfo("Story", Para % (MN1, O1, N1, N2, N3, S1, MN2, V1, WN1, BP1, V2, N4, N5, RN1, HM1, V3, N6, N7, N8, V4, N9, A1, A2, E1, V5, N10, N11, V6))
    root.update()





Next = Button(root, text="Next", command=Next)#buttons
Next.pack(side='right')
Back = Button(root, text="Back", command=Back)
Back.pack(side='left')






root.mainloop()

Any help would be greatly appreciated. I have tried to fix it before asking but my problem is pretty specific and i couldn't find anything. Thanks for the input.

asked 58 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: جمعه 25 تير 1395 ساعت: 9:00

صفحه بندی