Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7573515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:12:09+00:00 2026-05-30T16:12:09+00:00

What is wrong with this program? Every time I run it the first math

  • 0

What is wrong with this program? Every time I run it the first math problem is show before I push start. Also the answer is always the first math problem, it never changes. Also there should not be a math problem above the timer. Thanks, Scott

from Tkinter import*
import time
import tkMessageBox
import random

def Questions():    
    number1 = random.randrange(1,25)
    number2 = random.randrange(1,50)
    answer = number1 + number2
    prompt = ("Add " + str(number1) + " and " + str(number2))
    label1 = Label(root, text=prompt, width=len(prompt), bg='yellow')
    label1.pack()
    return answer

def start():
    global count_flag 
    Questions()
    count_flag = True
    count = 0.0
    while True:
        if count_flag == False:
            break
        # put the count value into the label
        label['text'] = str(count)
        # wait for 0.1 seconds
        time.sleep(0.1)
        # needed with time.sleep()
        root.update()
        # increase count
        count += 0.1

def Submit(answer, entryWidget):
     """ Display the Entry text value. """
     global count_flag

     count_flag = False
     print answer

     if entryWidget.get().strip() == "":
         tkMessageBox.showerror("Tkinter Entry Widget", "Please enter a number.")

     if answer != int(entryWidget.get().strip()):
         tkMessageBox.showinfo("Answer", "INCORRECT!")
     else:
         tkMessageBox.showinfo("Answer", "CORRECT!")



# create a Tkinter window
root = Tk()

root.title("Math Quiz")
root["padx"] = 40
root["pady"] = 20   

# Create a text frame to hold the text Label and the Entry widget
textFrame = Frame(root)

#Create a Label in textFrame
entryLabel = Label(textFrame)
entryLabel["text"] = "Answer:"
entryLabel.pack(side=LEFT)

# Create an Entry Widget in textFrame
entryWidget = Entry(textFrame)
entryWidget["width"] = 50
entryWidget.pack(side=LEFT)

textFrame.pack()

#directions     
directions = ('Click start to begin. You will be asked a series of questions.')
instructions = Label(root, text=directions, width=len(directions), bg='orange')
instructions.pack()

# this will be a global flag
count_flag = True

answer = Questions()

Sub = lambda: Submit(answer, entryWidget)
#stopwatch = lambda: start(answer)

# create needed widgets
label = Label(root, text='0.0')
btn_submit = Button(root, text="Submit", command = Sub)
btn_start = Button(root, text="Start", command = start)
btn_submit.pack()
btn_start.pack()
label.pack()


# start the event loop
root.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:12:10+00:00Added an answer on May 30, 2026 at 4:12 pm

    Your problem is with how you’re calling the Questions() method. You only ask for the answer once with

    answer = Questions()
    

    and you do this before you press start (which is why it shows up before you hit start)

    To fix it you could use code like this:

    from Tkinter import*
    import time
    import tkMessageBox
    import random
    
    def Questions():    
        number1 = random.randrange(1,25)
        number2 = random.randrange(1,50)
        answer = number1 + number2
        prompt = ("Add " + str(number1) + " and " + str(number2))
        label1 = Label(root, text=prompt, width=len(prompt), bg='yellow')
        label1.pack()
        return answer
    
    def start():
        global count_flag 
        global answer
        answer = Questions()
        count_flag = True
        count = 0.0
        while True:
            if count_flag == False:
                break
            # put the count value into the label
            label['text'] = str(count)
            # wait for 0.1 seconds
            time.sleep(0.1)
            # needed with time.sleep()
            root.update()
            # increase count
            count += 0.1
    
    def Submit(answer, entryWidget):
         """ Display the Entry text value. """
         global count_flag
    
         count_flag = False
         print answer
    
         if entryWidget.get().strip() == "":
             tkMessageBox.showerror("Tkinter Entry Widget", "Please enter a number.")
    
         if answer != int(entryWidget.get().strip()):
             tkMessageBox.showinfo("Answer", "INCORRECT!")
         else:
             tkMessageBox.showinfo("Answer", "CORRECT!")
    
    
    
    # create a Tkinter window
    root = Tk()
    
    root.title("Math Quiz")
    root["padx"] = 40
    root["pady"] = 20   
    
    # Create a text frame to hold the text Label and the Entry widget
    textFrame = Frame(root)
    
    #Create a Label in textFrame
    entryLabel = Label(textFrame)
    entryLabel["text"] = "Answer:"
    entryLabel.pack(side=LEFT)
    
    # Create an Entry Widget in textFrame
    entryWidget = Entry(textFrame)
    entryWidget["width"] = 50
    entryWidget.pack(side=LEFT)
    
    textFrame.pack()
    
    #directions     
    directions = ('Click start to begin. You will be asked a series of questions.')
    instructions = Label(root, text=directions, width=len(directions), bg='orange')
    instructions.pack()
    
    # this will be a global flag
    count_flag = True
    
    
    Sub = lambda: Submit(answer, entryWidget)
    #stopwatch = lambda: start(answer)
    
    # create needed widgets
    label = Label(root, text='0.0')
    btn_submit = Button(root, text="Submit", command = Sub)
    btn_start = Button(root, text="Start", command = start)
    btn_submit.pack()
    btn_start.pack()
    label.pack()
    
    
    # start the event loop
    root.mainloop()
    

    In this code the answer is updated every time you hit start and only updates when you hit start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This snippet of Perl code in my program is giving the wrong result. $condition
Usually every time `make install' is run, files are not put in a specific
Here is the story. I was doing a program, every time the program is
I have no idea what is wrong! This is a very simple program and
Whats wrong with this code? -(void) drawRect:(CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); if
Whats wrong with this picture? Model: validates_acceptance_of :terms_of_service, :on => :create, :accept => true,
whats wrong with this? anybody help me please.. if(stripos($nerde, $hf) !== false) && (stripos($nerde,
What's wrong with this query: INSERT INTO Users( weight, desiredWeight ) VALUES ( 160,
What's wrong with this function: function() { $.get('/controller/action', function(data) { $('#temporaryPhotos').text(data); } ); return
There is something wrong with this trigger. But what? CREATE TRIGGER MYCOOLTRIGGER AFTER INSERT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.