ModuleNotFoundError: No module named 'playsound' what to do? - python

I've been editing this mp3 player, but this error keeps apearing
from tkinter import *
from tkinter import messagebox
import playsound
#making the window
window = Tk()
window.title("button")
window.geometry("350x450+500+200")
#making the song fuction
def song():
playsound ("lights.mp3")
# making texbox
def InitialMessage():
name = name_Tf.get()
mood = mood_Tf.get()
#mood happy
if mood == "happy":
return messagebox.showinfo("message",
f"""Hi! {name}, wellcome.
may I intrest you with some music?""",
#making the song executer
button1 = Button(messagebox,
text="yes",
command=song,
font= ("Comic Sans", 15 )))
I don't have python 2 on the pc anymore, I uninstalled it, I have tried reinstaling playsound, as well as change the interpreter to the recomended, I dunno what to do anymore, please help

Try importing playsound with PIP
pip install playsound
And include in your code
from playsound import playsound
playsound('/path/to/a/sound/file/you/want/to/play.mp3')

Related

setting the resolution of my video in tkVideoPlayer is making the video run slowly

Im Using tkVideoPlayer To Run A Video In My Tkinter Program and when i set the resolution to 1920x1080 the video starts playing extremely slowly, and if i dont set the specific resolution myself it becomes very small(Very Small), but it runs normally. keep in mind that the resolution of the video im using is already 1920x1080. can someone help me?
Source Code ATM:
import time
import os
from subprocess import call
from playsound import playsound
import pygame
from pygame import mixer
import tkinter as tk
from tkinter import *
from tkVideoPlayer import TkinterVideo
def introBIORUNNERDEF():
#Setup For Previewing
root = Tk()
root.title('SNCC3')
root.geometry("1920x1080")
root.config(bg="black")
def BIOSCYCLEDEF():
bioInt1Frame = tk.Frame(root, bg="black")
bioInt1Frame.place(relwidth=1, relheight=1, rely=0)
#bioInt2Frame = tk.Frame(root, bg="black")
#bioInt2Frame.place(relwidth=1, relheight=1)
bioInt1 = TkinterVideo(master=bioInt1Frame,scaled=True)
bioInt1.load(r"ViD/BIOINTFULL.mp4")
bioInt1.pack(expand=True,fill="both")
bioInt1.play()
#bioInt2Frame.place(relwidth=1, relheight=1, rely=0)
#bioInt2 = TkinterVideo(master=bioInt2Frame,scaled=True)
#bioInt2.load(r"ViD/BIOINTFULL.mp4")
#bioInt2.pack(expand=True,fill="both")
#bioInt2.play()
BIOSCYCLEDEF()
root.mainloop()
introBIORUNNERDEF()
I dont know what to try, i tried following the guide and following a tutorial video but still nothing.

How to properly import tcl file

I am trying to use the Azure theme in a tkinter application i made. I used the code from github to import the theme(https://github.com/rdbende/Azure-ttk-theme). I put the "azure.tcl" file in the folder with the python file and got the error "_tkinter.TclError: couldn't read file "./theme/light.tcl": no such file or directory". I then tried making a simpler tkinter program with the same ttk theme import code from before but this time in it's own folder with the tcl file. I still got the same error message. When i download the file from github, i ran the example python file and worked just fine.
Here is the code i use to import the file.
import tkinter as tk
from tkinter import Label, ttk
root = tk.Tk()
root.tk.call("source", "azure.tcl")
root.tk.call("set_theme", "dark")
root.geometry("300x300")
L1 = Label(root, text="Hello world")
L1.grid(row=1, column=1)
root.mainloop()
If you do not have this "TKinterModernThemes" library, then you should also install it with below code:
pip install TKinterModernThemes
Then, you can keep your script as it is but just a few arrangements.
Importing Library:
import TKinterModernThemes as TKMT
Threat like window.root is your tk.Tk() object:
import tkinter as tk
from tkinter import Label, ttk
import TKinterModernThemes as TKMT
window = TKMT.ThemedTKinterFrame("%yourProjectName","azure","dark")
window.root.geometry("300x300")
L1 = Label(window.root, text="Hello world")
L1.grid(row=1, column=1)
window.root.mainloop()

I'm using tkinter GUI and winsound but stop function is not working

from tkinter import *
import winsound
from winsound import PlaySound, SND_FILENAME, SND_LOOP, SND_ASYNC
root = Tk()
root.configure(background='light green')
def playing():
winsound.PlaySound('alarm', winsound.SND_FILENAME)
def stop_sound():
PlaySound(None, SND_FILENAME)
Button(root,text="playing ",font=("Helvetica 15"),command=playing).pack(pady=20)
Button(root,text="Stop",font=("Helvetica 15"),command=stop_sound).pack(pady=20)
root.mainloop()
Fix Updated
In your playing function
You can replace winsoud.PlaySound and winsound.SND_FILENAME with PlaySound and SND_FILENAME.
The complete code will look like this
from tkinter import *
from winsound import PlaySound, SND_FILENAME, SND_LOOP, SND_ASYNC
root = Tk()
root.configure(background='light green')
def playing(): PlaySound('alarm', SND_FILENAME)
def stop_sound(): PlaySound(None, SND_FILENAME)
Button(root,text="playing ",font=("Helvetica 15"),command=playing).pack(pady=20)
Button(root,text="Stop",font=("Helvetica 15"),command=stop_sound).pack(pady=20)
root.mainloop()
Description
The idea is same. The program doesn't know what winsound is since we are not importing it. But the functions we are calling are imported. So no need to prefix them with winsound.
Fix
Include this line with other imports
import winsound
Description
From looking at the code you are not importing the 'winsound' module. You are including from it by not the module itself.
Note
When asking question on StackOverflow kindly share your exceptions/log messages so people can help you easily

Is Playsound able to play two sounds at the same time?

When you press e it will play the sound, which is fine. But when you try to press it while the sound is active it waits until the sound is done to play it again. I need the sounds to be played at the same time.
import tkinter
from playsound import playsound
root = tkinter.Tk()
def key_pressed(event):
playsound('sound.wav')
root.bind("<Key>", key_pressed)
root.mainloop()
Try this:
import tkinter
from playsound import playsound
root = tkinter.Tk()
def key_pressed(event):
playsound('sound.wav', block=False)
root.bind("<Key>", key_pressed)
root.mainloop()

ModuleNotFoundError: No module named 'tkSimpleDialog' - Python Shell

I'm trying to run this code which I got here:
from tkinter import *
import tkSimpleDialog
import tkMessageBox
root = Tk()
w = Label(root, text= "My Program")
w.pack()
tkMessageBox.showinfo("Welcome", "Add welcome message here")
but this
error occured:
I already look here ModuleNotFoundError: No module named x, but I can't understand the answers. I'm still new about these stuff.
If you are using python 3, you will need to import it as tkinter.simpledialog. Likewise, MessageBox has been changed to tkinter.messagebox.

Categories

Resources