import pygame from tkinter import * # Initialize Pygame pygame.init() pygame.mixer.init() # Explicitly initialize the mixer def play(): pygame.mixer.music.load('background.wav') # Make sure the path is correct pygame.mixer.music.play() def pause(): pygame.mixer.music.pause() def unpause(): pygame.mixer.music.unpause() def sound(): sound_effect.play() # Load sound effects sound_effect = pygame.mixer.Sound('crash.wav') # Ensure file path is correct # Set up the tkinter root window root = Tk() root.geometry('180x200') # Create a frame and label inside the root window myframe = Frame(root) myframe.pack() mylabel = Label(myframe, text="Pygame Mixer") mylabel.pack() # Create buttons with commands that trigger functions button1 = Button(myframe, text="Play", command=play, width=15) button1.pack(pady=5) button2 = Button(myframe, text="Sound", command=sound, width=15) button2.pack(pady=5) button3 = Button(myframe, text="Unpause", command=unpause, width=15) button3.pack(pady=5) button4 = Button(myframe, text="Pause", command=pause, width=15) button4.pack(pady=5) # Start the tkinter main loop root.mainloop()