mardi 28 décembre 2021

how to make a checkbox and check the state of it(if its correct or no)

hello i want to make 3 checkboxes one saying cpu, one saying gpu and one saying cll and i want to check if the answer is correct so can u show me how to do that

import time
import tkinter as tk

import pygame

window = tk.Tk()
pygame.mixer.init()
img = tk.PhotoImage(file='C:\\Users\\laithmaree\\PycharmProjects\\create_apps_with_python\\brainicon.ico.png')
window.title("Quiz Game")
# pygame.mixer.music.load('ForestWalk-320bit.wav')
# pygame.mixer.music.play()
# i created an icon
# i made a title


window.geometry("800x600")
window.resizable(width=False, height=False)
window.iconphoto(False, img)


label1 = tk.Label(window, text='Quiz App', font=("Arial Bold", 25))
label1.pack()

txtbox = tk.Entry(window, width=50)


def playbuttonclicked():
    label1.destroy()
    playbtn.destroy()
    quitbtn.destroy()
    label2 = tk.Label(window, text='What is the short form of computer science',font=("Arial Bold", 25))
    label2.pack()
    txtbox.place(x=250, y=200, height=40)

    def chkanswer():
        useranswer = txtbox.get()  # Get contents from Entry
        if useranswer == 'cs':
            lblcorrect = tk.Label(window, text='correct', )
            lblcorrect.pack()
            def delete():
                lblcorrect.destroy()
                label2.destroy()
                txtbox.destroy()
                submitbtn.destroy()
                label3 = tk.Label(window, text='whats is the short form of central proccessing unit', font=('Arial Bold', 25))
                label3.pack()
            lblcorrect.after(1001, delete)

        else:
            lblwrong = tk.Label(window, text='Try Again')
            lblwrong.pack()

            def deletefunction():
                lblwrong.destroy()

            lblwrong.after(1000, deletefunction)









    submitbtn = tk.Button(window, text='Submit', font=('Arial Bold', 30), command=chkanswer, bg='red')
    submitbtn.place(x=305, y=400)
    submitbtn.bind('<Enter>', lambda e: e.widget.config(bg='grey'))
    submitbtn.bind('<Leave>', lambda e: e.widget.config(bg='red'))


playbtn = tk.Button(window, text='Play', font=("Arial Bold", 90), bg='red', command=playbuttonclicked)
playbtn.place(x=10, y=200)
playbtn.bind('<Enter>', lambda e: e.widget.config(bg='grey'))
playbtn.bind('<Leave>', lambda e: e.widget.config(bg='red'))


def quitbuttonclicked():
    window.destroy()


quitbtn = tk.Button(window, text='Quit', font=("Arial Bold", 90), bg='red', command=quitbuttonclicked)
quitbtn.place(x=400, y=200)
quitbtn.bind('<Enter>', lambda e: e.widget.config(bg='grey'))
quitbtn.bind('<Leave>', lambda e: e.widget.config(bg='red'))
window.mainloop()

the question is label 3 (whats is the short form of central proccessing unit) and i want to make sure the answer is correct because i am creating a quiz app thx




Aucun commentaire:

Enregistrer un commentaire