# Importing the necessary modules import pygame # Module for game development from tkinter import * # Module for creating GUI applications # Function to play the background music def play(): pygame.mixer.music.load('background.mp3') # Loading the background music file pygame.mixer.music.play() # Playing the background music # Function to pause the background music def pause(): pygame.mixer.music.pause() # Pausing the background music # Function to unpause the background music def unpause(): pygame.mixer.music.unpause() # Unpausing the background music # Function to play a sound effect def sound(): pygame.mixer.Sound.play(sound_effect) # Playing the specified sound effect # Initializing the pygame module pygame.init() # Loading a sound effect sound_effect = pygame.mixer.Sound('crash.mp3') # Creating the main window using tkinter root = Tk() root.geometry('180x200') # Setting the geometry of the window # Creating a frame within the main window myframe = Frame(root) myframe.pack() # Creating a label widget for displaying text mylabel = Label(myframe, text="Pygame Mixer") mylabel.pack() # Creating buttons for different actions with specified text, commands, and widths 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) # Running the main event loop to display the window root.mainloop()