#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0

    Entry widget help


    Hello,
    So I'm having this problem with my entry widget. I have looked up many web sites but I just cant get it to work. What I am trying to do is have the program read the input the user put in and see if the input is the same as the real answer.
    I know that some of the code below is not needed but I just need help on callback 4.
    Code:
    from Tkinter import *
    root = Tk()
    rank=0
    points=0
    root.geometry("900x1000+200+200")
    root.title("Math Game")
    var = StringVar()
    var2= StringVar()
    var3= StringVar()
    var4= StringVar()
    var5= StringVar()
    var6= StringVar()
    var7= StringVar()
    var8= StringVar()
    label1=Label(root, textvariable=var, relief=RAISED)
    var.set ("Welcome To the Math Game set 1")
    label1.pack()
    label2=Label(root, textvariable=var2, relief=RAISED)
    var2.set("Main Menu")
    label2.pack()
    def callback1():
        label3=Label(root, textvariable=var3, relief=RAISED)
        var3.set("About The Game:")
        label3.pack()
        label4=Label(root, textvariable=var4, relief=RAISED)
        var4.set("The Math Game is a good way to learn how to do math facts as well as doing the problems your self. There is also games with it!")
        label4.pack()
    
    def callback2():
        label5=Label(root, textvariable=var5, relief=RAISED)
        var5.set("Rank: " + str (rank))
        label5.pack()
    
    def callback3():
        label6=Label(root, textvariable=var6, relief=RAISED)
        var6.set("(10 rank = 1 point) Points are used to buy more levels and earn many differnt things. you have " + str (points) + " Points!")
        label6.pack()
    
    def callback4():
        label7=Label(root, textvariable=var7, relief=RAISED)
        var7.set("You are about to start the game!")
        label7.pack()
        Loading=0
        import random
        Questiona = random.randint(1, 10)
        Questionab = random.randint(1, 10)
        Questionaanswerreal = Questiona + Questionab
        label8 = Label(root, textvariable=var8, relief=RAISED)
        var8.set("Question 1: " + str (Questiona) + " + " + str (Questionab) + " = ?")
        label8.pack()
        Questionaansweruser = Entry(root)
        Questionaansweruser.pack()
        Questionaansweruser.get() 
        def callback5():
            if Questionaansweruser == str(Questionaanswerreal):
                print ("test")
        b = Button(root, text="get", width=5, command=callback5)
        b.pack()
        
            
    b3=Button(root, text="Play Game", command=callback4)
    b3.pack()
    b2=Button(root, text="Points", command=callback3)
    b2.pack()     
    b1=Button(root, text="Rank", command=callback2)
    b1.pack()
    b=Button(root, text="About The Game", command=callback1)
    b.pack()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    Just change the code around callback5 to this and you'll have the best, most exciting math quiz ever devised.
    Code:
        Questionaansweruser = Entry(root)
        Questionaansweruser.pack()
        def callback5():
            if Questionaansweruser.get() == str(Questionaanswerreal):
                print ("test")
            else:
                print('test----fail')
        b = Button(root, text="get", width=5, command=callback5)
        b.pack()
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo