I want to make a sound button that deletes itself and plays music, while making a new mute button and vice versa. Python-Turtle what's wrong with my code?
import turtle, random, math
from turtle import*
from tkinter import*
import winsound
def playsound():
winsound.PlaySound('mainmenu.wav',winsound.SND_LOOP + winsound.SND_ASYNC)
bsound.pack()
bsound.place(x=600,y=400)
def stopsound():
winsound.PlaySound(None, winsound.SND_PURGE)
bsound.pack_forget()
bsound.place_forget()
bmute.pack()
bmute.place(x=600,y=400)
bsound=Button(root, image=bsoundpic, command = stopsound)
bmute=Button(root, image=bmutepic, command = playsound)
You're creating
bsoundandbmutebuttons and you're also attempting to pack them in theplaysoundandstopsoundfunctions, but the buttons dont exist before those function are run.Also you are using
bsoundpicandbmutepicimages without defining themLets create the buttons first and then pack them or place them in your functions.