Question

In: Computer Science

I did the complete programming in python , just want to use tkinter for GUI. please...

I did the complete programming in python , just want to use tkinter for GUI. please look at the 2nd part . i did some part of this program using tkinter but could not finis it. Thank you.

import random

image = 'w'
# modified functions which accepts two numbers each and returns the respective
# output
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b



def kidCalc():
    a = random.randint(0, 9)
    b = random.randint(0, 9)

    print("0. Exit")
    print("1. Add")
    print("2. Subtract")
    print("3. Multiply")
    choice = int(input("Enter choice: "))
    cnt = 0  # To hold number of tries
    if choice == 1:
        while True:
            print(" what do you think the sum of these two numbers are? ", a, " + ", b)
            print("This is how it looks viually", a * image, "+ ", b * image)

            sum = input()
            answer = int(sum)
            if answer == add(a, b):
                print("Perfect, the answer is correct...")
                cont = input("\nIf you want to solve another question then press 1. If not then any other key ")
                if cont == "1":
                    a = random.randint(0, 9)
                    b = random.randint(0, 9)
                    cnt = 0
                    continue
                else:
                    break

            elif answer != add(a, b):
                print("I am sorry, your answer is wrong Sean,Please Try again:")
                # Incrementing count
                cnt = cnt + 1
                # Checking count
                if cnt == 3:
                    # Prompting for next try
                    ans = input("\nMax number of tries reached. Do you want to try another question or quit? (T/Q): ")
                    # Checking answer
                    if ans.upper() == "T":
                        a = random.randint(0, 9)
                        b = random.randint(0, 9)
                        continue
                    else:
                        print('Bye!')
                        break

                else:
                    continue

    if choice == 2:
        while True:
            print(" what do you think the sum of these two numbers are? ", a, " - ", b)
            print("This is how it looks viually", a * image, "- ", b * image)

            sub = input()
            answer = int(sub)
            if answer == subtract(a, b):
                print("Perfect, the answer is correct...")
                cont = input("\nIf you want to solve another question then press 1. If not then any other key ")
                if cont == "1":
                    a = random.randint(0, 9)
                    b = random.randint(0, 9)
                    cnt = 0
                    continue
                else:
                    break

            elif answer != subtract(a, b):
                print("I am sorry, your answer is wrong Sean,Please Try again:")
                # Incrementing count
                cnt = cnt + 1
                # Checking count
                if cnt == 3:
                    # Prompting for next try
                    ans = input("\nMax number of tries reached. Do you want to try another question or quit? (T/Q): ")
                    # Checking answer
                    if ans.upper() == "T":
                        a = random.randint(0, 9)
                        b = random.randint(0, 9)
                        continue
                    else:
                        print('Bye!')
                        break

                else:
                    continue
    if choice == 3:
        while True:
            print(" what do you think the sum of these two numbers are? ", a, " - ", b)
            print("This is how it looks viually", a * image, "- ", b * image)

            mult = input()
            answer = int(mult)
            if answer == multiply(a, b):
                print("Perfect, the answer is correct...")
                cont = input("\nIf you want to solve another question then press 1. If not then any other key ")
                if cont == "1":
                    a = random.randint(0, 9)
                    b = random.randint(0, 9)
                    cnt = 0
                    continue
                else:
                    break

            elif answer != multiply(a, b):
                print("I am sorry, your answer is wrong Sean,Please Try again:")
                # Incrementing count
                cnt = cnt + 1
                # Checking count
                if cnt == 3:
                    # Prompting for next try
                    ans = input("\nMax number of tries reached. Do you want to try another question or quit? (T/Q): ")
                    # Checking answer
                    if ans.upper() == "T":
                        a = random.randint(0, 9)
                        b = random.randint(0, 9)
                        continue
                    else:
                        print('Bye!')
                        break

                else:
                    continue

kidCalc()

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

from tkinter import *
import random

# FUNCTION
def calc_For_Kids():
    # create the tk
    var1 = Tk()
    var1.title("Kitty Calculator")
    var1.geometry('450x450')
    # generate the two numbers
    numb1 = random.randint(0, 9)
    numb2 = random.randint(0, 9)

    # ask usr for sum
    temp = ("what do you think the sum of these two number is : " + str(numb1) + "+" + str(numb2))

    # label
    qLabel = Label(var1, text=temp)
    qLabel.grid(row=0, column=0)

    qLabel1 = Label(var1, text="")
    qLabel1.grid(row=1, column=0)

    userEntry = Entry(var1)
    userEntry.grid(row=2, column=0)

    qLabel4 = Label(var1, text="")

    # function for checking the result
    def func():
        textEntered = int(userEntry.get())
        if ((numb1 + numb2) == textEntered):
            qLabel4.configure(text="Perfect, the answer is correct:")

        else:
            qLabel4.configure(text="i am so sorry , your answer is wrong kitto: Try again : ")

    # label for spacing
    qLabel2 = Label(var1, text="")
    qLabel2.grid(row=3, column=0)

    ok_Button = Button(var1, text="OK", command=func)
    ok_Button.grid(row=4, column=0, columnspan=2)

    qLabel3 = Label(var1, text="")
    qLabel3.grid(row=5, column=0)

    # label for result
    qLabel4.grid(row=6, column=0)

    qLabel5 = Label(var1, text="")
    qLabel5.grid(row=7, column=0)

    var1.mainloop()


# PROGRAM EXECUTION STARTS HERE
calc_For_Kids()

Solutions

Expert Solution

import random
from tkinter import *


# FUNCTION


def calc_For_Kids():
    # create the tk
    root = Tk()
    root.title("Kitty Calculator")
    root.geometry('450x450')
    root.config(bg="white")

    def addFunc():
        def checkAdd():
            if (addEntry.get() == str(a + b)):
                addlabel3 = Label(root, text="\nPerfect, the answer is correct... \n"
                                             "If you want to solve another question then press option button again.\n"
                                             " If not then press any other option ", bg="white")
                addlabel3.grid(row=10, column=0, padx=20)
            else:
                addlabel3 = Label(root, text="\nSorry, the answer is wrong... Please try again !\n"
                                             "If you want to solve another question then press option button again.\n"
                                             " If not then press any other option ", bg="white")
                addlabel3.grid(row=10, column=0, padx=20)

        a = random.randint(0, 9)
        b = random.randint(0, 9)
        addlabel1 = Label(root, text="what do you think the sum of these two numbers are? ", bg="white")
        num = f"{a} + {b}"
        addlabel2 = Label(root, text=num, bg="white")
        addEntry = Entry(root)
        addButton = Button(root, text=" Submit ", command=checkAdd)
        message = "\n\nIf you want to solve another question then press option button again.\n if not then press any other option "
        addlabel3 = Label(root, text=message, bg="white")
        addlabel3.grid(row=10, column=0, padx=20)
        addlabel1.grid(row=6, column=0, pady=5, padx=20)
        addlabel2.grid(row=7, column=0, pady=5, padx=20)
        addEntry.grid(row=8, column=0, pady=5, padx=20)
        addButton.grid(row=9, column=0, pady=5, padx=20)

    def subFunc():
        def checkSub():
            if (subEntry.get() == str(a - b)):
                sublabel3 = Label(root, text="\nPerfect, the answer is correct... \n"
                                             "If you want to solve another question then press option button again.\n"
                                             " If not then press any other option ", bg="white")
                sublabel3.grid(row=10, column=0, padx=20)
            else:
                sublabel3 = Label(root, text="\nSorry, the answer is wrong... Please try again !\n"
                                             "If you want to solve another question then press option button again.\n"
                                             " If not then press any other option ", bg="white")
                sublabel3.grid(row=10, column=0, padx=20)

        a = random.randint(0, 9)
        b = random.randint(0, 9)
        sublabel1 = Label(root, text="what do you think the difference of these two numbers are? ", bg="white")
        subnum = f"{a} - {b}"
        sublabel2 = Label(root, text=subnum, bg="white")
        subEntry = Entry(root)
        subButton = Button(root, text=" Submit ", command=checkSub)
        message = "\n\nIf you want to solve another question then press option button again.\n if not then press any other option "
        sublabel3 = Label(root, text=message, bg="white")
        sublabel3.grid(row=10, column=0, padx=20)
        sublabel1.grid(row=6, column=0, pady=5, padx=20)
        sublabel2.grid(row=7, column=0, pady=5, padx=20)
        subEntry.grid(row=8, column=0, pady=5, padx=20)
        subButton.grid(row=9, column=0, pady=5, padx=20)

    def mulFunc():
        def checkMul():
            if (mulEntry.get() == str(a * b)):
                mullabel3 = Label(root, text="\nPerfect, the answer is correct... \n"
                                             "If you want to solve another question then press option button again.\n"
                                             " If not then press any other option ", bg="white")
                mullabel3.grid(row=10, column=0, padx=20)
            else:
                mullabel3 = Label(root, text="\nSorry, the answer is wrong... Please try again !\n"
                                             "If you want to solve another question then press option button again.\n"
                                             " If not then press any other option ", bg="white")
                mullabel3.grid(row=10, column=0, padx=20)

        a = random.randint(0, 9)
        b = random.randint(0, 9)
        mullabel1 = Label(root, text="what do you think the difference of these two numbers are? ", bg="white")
        mulnum = f"{a} * {b}"
        mullabel2 = Label(root, text=mulnum, bg="white")
        mulEntry = Entry(root)
        mulButton = Button(root, text=" Submit ", command=checkMul)
        message = "\n\nIf you want to solve another question then press option button again.\n if not then press any other option "
        mullabel3 = Label(root, text=message, bg="white")
        mullabel3.grid(row=10, column=0, padx=20)
        mullabel1.grid(row=6, column=0, pady=5, padx=20)
        mullabel2.grid(row=7, column=0, pady=5, padx=20)
        mulEntry.grid(row=8, column=0, pady=5, padx=20)
        mulButton.grid(row=9, column=0, pady=5, padx=20)

    def exitFunc():
        exit()

    # menu
    label5 = Label(root, text="Please click on the options below : ", bg="white", fg="#003366")
    label1 = Button(root, text="1. Add", bg="#003366", fg="white", width=20, command=addFunc)
    label2 = Button(root, text="2. Subtract", bg="#003366", fg="white", width=20, command=subFunc)
    label3 = Button(root, text="3. Multiply", bg="#003366", fg="white", width=20, command=mulFunc)
    label4 = Button(root, text="0. Exit", bg="#003366", fg="white", width=20, command=exitFunc)
    label6 = Label(root, bg="white")

    label1.grid(row=1, column=0, pady=(5, 5), padx=150)
    label2.grid(row=2, column=0, pady=5, padx=20)
    label3.grid(row=3, column=0, pady=5, padx=20)
    label4.grid(row=4, column=0, pady=5, padx=20)
    label5.grid(row=0, column=0, pady=(50, 5), padx=20)
    label6.grid(row=5, column=0, pady=5, padx=20)

    root.mainloop()


# PROGRAM EXECUTION STARTS HERE
calc_For_Kids()

Related Solutions

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate...
Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as...
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter...
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter and no other GUI product. Design a small (ie 2x3) GUI window which contains 4 items: 1. A text keyin field, 2. An Execute button, 3. An Exit Button 4. A label. When the user clicks on the execute button, the text located in the keyin field will be displayed on the label. If the keyin field contains no text, a message box should...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): A website requests an user to input his account password. Write a program to examize the validity of the password. The valid password must consists of: At least 1 letter in [a-z] At least 1 number in [0-9] At least a letter in [A-Z] (capital) At least one special letter in [$#@] At least...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA is >= 3.5, display 'Dean’s List' If the GPA is < 2.0, display 'Probation’ If the GPA is < 3.5 and >= 2.0, display 'Regular Standing' Run one test case for each case above and save the output.
In python using tkinter, I want to create a program. The program can have various classes...
In python using tkinter, I want to create a program. The program can have various classes and methods but I want it to have circles, triangles, and squares. Each shape movies in a certain way, like circles can move linearly, triangles can be affected by gravity, and squares can only go up and down. If the shapes get too close to one another then they disappear and a new shape appears somewhere else. I want this program to run continuously.
PLEASE I DONT WANT PICTURES FOR MY QUESTION JUST COPY PAST AS I DID HERE THANK...
PLEASE I DONT WANT PICTURES FOR MY QUESTION JUST COPY PAST AS I DID HERE THANK YOU FOR UNDERSTANDING. Assignment Question(s):                                                      Q1- A company wants to implement good internal control. What are the policies and procedures you can suggest to minimize human frauds and errors? (1Mark) Q2- Assume that you have a company. And the management team estimates that 3% of sales will be uncollectible. Give any amount of sales and prepare the journal entry using the percent of sales...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar,...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar, and a Menu bar FOR THE QUESTION BELOW: PLEASE HELP PROGRAMMING LANGUAGE IS PYTHON Write a simple quiz game that has a list of ten questions and a list of answers to those questions. The game should give the player four randomly selected questions to answer. It should ask the questions one-by-one, and tell the player whether they got the question right or wrong....
PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and...
PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and labels and an overall theme. # Meet the chatbot Eve print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!') print(' ') print('Lets get started') #begin questions firstName = input('What is your first name?: ') lastName = input('What is your last name? ') print("Hi there, ", firstName + lastName,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT