Generation

fix invalid codeWed, 10 May 2023

import tkinter as tk import winsound # Global variables math_questions = [ "2 + 2 = ?", "5 + 3 = ?", "10 - 4 = ?", "6 * 2 = ?", "12 / 3 = ?" ] current_question = 0 # Function to start the image scramble game def start_image_scramble(): window.destroy() image_scramble_window() # Function to start the math game def start_math_game(): window.destroy() open_math_window() # Function to open the math game window def open_math_window(): global current_question current_question = 0 math_window = tk.Tk() math_window.title("Math Game") math_window.geometry("400x400") def display_question(): global current_question if current_question >= len(math_questions): result_label.config(text="Congratulations! You answered all the questions.") answer_entry.config(state=tk.DISABLED) next_button.config(state=tk.DISABLED) return question_label.config(text=math_questions[current_question]) answer_entry.delete(0, tk.END) answer_entry.focus_set() next_button.config(state=tk.DISABLED) current_question += 1 def submit_answer(): user_answer = answer_entry.get().strip() correct_answer = eval(math_questions[current_question - 1].split("=")[0].strip()) if user_answer.isdigit() and int(user_answer) == correct_answer: result_label.config(text="Correct!") else: result_label.config(text="Incorrect!") answer_entry.delete(0, tk.END) next_button.config(state=tk.NORMAL) answer_entry.focus_set() question_label = tk.Label(math_window, text="", font=("Arial", 16)) question_label.pack(pady=20) answer_label = tk.Label(math_window, text="Enter your answer:", font=("Arial", 14)) answer_label.pack() answer_entry = tk.Entry(math_window, font=("Arial", 14), width=10) answer_entry.pack(pady=10) submit_button = tk.Button(math_window, text="Submit", font=("Arial", 12), command=submit_answer) submit_button.pack() result_label = tk.Label(math_window, text="", font=("Arial", 16)) result_label.pack(pady=20) next_button = tk.Button(math_window, text="Next", font=("Arial", 12), command=display_question) next_button.pack() next_button.config(state=tk.DISABLED) display_question() # Function to start the image scramble game window def image_scramble_window(): # Image Scramble game code pass def open_image_scramble_window(): image_scramble_window = tk.Tk() image_scramble_window.title("Fraction Scrambler") image_scramble_window.geometry("800x400") image_files = [ "01eighth.png", "02eighths.png", "03eighths.png", "04eighths.png", "05eighths.png", "06eighths.png", "07eighths.png", "08eighths.png" ] images = [] boxes = [] for i, image_file in enumerate(image_files): photo = tk.PhotoImage(file=image_file) photo = photo.subsample(2) image_label = tk.Label(image_scramble_window, image=photo) image_label.image = photo image_label.place(x=100 * i + 50, y=50) image_label.bind("<Button-1>", drag_start) image_label.bind("<B1-Motion>", drag_motion) image_label.bind("<ButtonRelease-1>", drop) images.append(image_label) box_label = tk.Label( image_scramble_window, text=f"{i+1}/8", font=("Arial", 12), relief="solid", width=10, height=5 ) box_label.place(x=100 * i + 50, y=250) boxes.append(box_label) correct_positions = { "1": (60, 270), "2": (162, 270), "3": (260, 270), "4": (362, 270), "5": (460, 270), "6": (563, 270), "7": (664, 270), "8": (764, 270) } check_button = tk.Button(image_scramble_window, text="Check", font=("Arial", 12), command=check_positions) check_button.place(x=150, y=350) result_label = tk.Label(image_scramble_window, text="", font=("Arial", 14)) result_label.place(x=100, y=375) image_scramble_window.mainloop() window = tk.Tk() window.title("Game Selection") window.geometry("400x200") winsound.PlaySound("OriginalDramaticGameMusic.wav", winsound.SND_ASYNC + winsound.SND_LOOP) image_scramble_button = tk.Button(window, text="Fraction Scrambler", font=("Arial", 16), command=open_image_scramble_window) image_scramble_button.place(relx=0.5, rely=0.3, anchor=tk.CENTER) math_game_button = tk.Button(window, text="Math Game", font=("Arial", 16), command=open_math_window) math_game_button.place(relx=0.5, rely=0.7, anchor=tk.CENTER) window.mainloop()

def add(a, b): return a + b

Want to kickstart your project?Use the new AI Studio to create your code