### Thread: Random question help

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

Join Date
Apr 2013
Posts
19
Rep Power
0

#### Random question help

Hello,
I'm having this problem with random questions. This is what I am trying to do. In normal python 3.3 I have a math game. The code below is what the questions look like in normal 3.3 python.
Code:
import random
Qa=random.randint(1, 10)
Qab=random.randint(1, 10)
print ('Question 1:   ' + str (Qa) +' + ' + str (Qab) + ' = ?') # separate the question number please!
Qbaa=input()      # Qba is a string
Qbaaa = Qa + Qab  # Qbaa is an integer
if Qbaa == str(Qbaaa):   # compare as strings.   str(Qbaa)
print ('Correct! + 25 to score!')
Score = Score + 25
print (Score)
else:
print ('Incorrect,  -25 to score!')
Score = Score - 25
print (Score)
That is what I'm trying to put in my Tkinter code.
Tkinter Code:
Code:
def callback5():
label = Label(root, textvariable=var, relief=RAISED)
var.set ("You are about to start the game!")
label.pack()
Qa=random.randint(1, 10)
Qab=random.randint(1, 10)
Qabb=Qa + Qab
label = Label(root, textvariable=var, relief=RAISED)
var.set ("Question 1: " + Qa + " + " + Qab + " = ? ")
label.pack()
if Qaanswer == "str Qabb":
label = Label(root, textvariable=var, relief=RAISED)
var.set ("Correct!")
label.pack()

b = Button(root, text="Play Game", command=callback5)
b.pack()
b = Button(root, text="Ranks", command=callback4)
b.pack()
b = Button(root, text="About the Game", command=callback3)
b.pack()
Thank you.
2. You keep creating the same label object.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2013
Posts
19
Rep Power
0
Originally Posted by Dietrich
You keep creating the same label object.
Well, sorry I guess I did not make my problem clear. I was wondering if
Code:
Qa = random.randint(1, 10)
Works in Tkinter?
4. Don't create the Tkinter.Label in the callback.
Do create them in the main code, just once.
In the callback change the value of the text variable.
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2013
Posts
19
Rep Power
0
Originally Posted by b49P23TIvg
Don't create the Tkinter.Label in the callback.
Do create them in the main code, just once.
In the callback change the value of the text variable.
okay I will try that if I know what you mean.