I am using VS code for my python and I am getting an error saying
'Traceback (most recent call last):
File "c:\Users\thecodeadd\OneDrive\Documents\Program\Python\Pyton programs\Fidget spinner.py", line 1, in <module>
import tkinter
File "c:\Users\thecodeadd\OneDrive\Documents\Program\Python\Pyton programs\tkinter.py", line 2, in <module>
win= Tk()
NameError: name 'Tk' is not defined'
I have repaired my python file and searched on the internet but I have not been able to find any solutions for this.
You didn't import the Tk class. Intead, you imported the tkinter module. To use the Tk class from the module you need to use win = tkinter.Tk().
It also looks like you named your file tkinter.py, which means that even if you do the above it won't work because your tkinter.py will get imported instead of the tkinter module. You should rename your file to something else besides tkinter.py.
Related
I am trying to make an exit button with the code
I do import tkinter* in here
from tkinter import*
from tkinter import ttk
from PIL import Image,ImageTk
import os
def iExit(self):
self.iExit=tkinter.askyesno("Face Recognition","Are you sure you want to exit?")
if self.iExit >0:
self.root.destroy()
else:
return
and I got the error
I know that I cant put tkinter inside the code but i don't know how to solve it. The error that I am getting is here
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "c:\Users\user\Desktop\FYP\Facial_Recognition system\Main.py", line 148, in iExit
self.iExit=tkinter.askyesno("Face Recognition","Are you sure you want to exit?")
^^^^^^^
NameError: name 'tkinter' is not defined
askyesno is defined in the tkinter.messagebox module. Import it from there:
from tkinter.messagebox import askyesno
I am not able to run a audio file automatically when the program started i saw playsound module but it is giving me error
Traceback (most recent call last):
File "main.py", line 7, in <module>
playsound('Music/videoplayback(2).mp3')
TypeError: 'module' object is not callable
my code
import random
import playsound
#Creating a KBC Special Quiz!
print("'\033[1m'"+"Welcome To Kaun Banega Crorepati!")
print()
print()
playsound('Music/videoplayback(2).mp3')
i am using repl, even i am finding difficulties in pathing
You are using the playsound module instead of the playsound.playsound function.
The docs show you how to import it so it works like you expected, see below.
>>> from playsound import playsound
>>> playsound('/path/to/a/sound/file/you/want/to/play.mp3')
import tailer
test = tailer.tail(open("test.txt"), 1)
#print(lines[1])
It's as simple as the code above, but it doesn't work.
(I saved it because it was successful once during the experiment, but an error occurs when I run it again later.)
Error content:
Traceback (most recent call last):
File "c:\Users\user\Documents\VSCODE\python\V1\tailer.py", line 1, in <module>
import tailer
File "c:\Users\user\Documents\VSCODE\python\V1\tailer.py", line 3, in <module>
test = tailer.tail(open("test.txt"), 1)
AttributeError: partially initialized module 'tailer' has no attribute 'tail' (most likely due to a circular import)
Looks like your file is called tailer.py, so when it does import tailer, it tries to load itself, which is usually a recipe for confusion.
You named your program tailer.py. When you do an import tailer the local folder has priority over all other folders and you will import tailer.py again. Creating an import circle.
In other words: you have a name clash between your program and the library you are trying to import. Just rename the file to something else and try again.
This question already has an answer here:
Python tkinter import error
(1 answer)
Closed 2 years ago.
Traceback (most recent call last):
File "tkinter.py", line 2, in <module>
from tkinter import *
File "C:\Users\mouad\Desktop\Project 2\tkinter.py", line 11, in <module>
mainwindow = Tk()
NameError: name 'Tk' is not defined
and when using python directly by running in cmd python I got no issue importing
It is not written like that, i advise you to do this :
from tkinter import *
root = Tk()
If i dont work chek if tkinter is well installed.
I use python 3.6, and I am trying to play an audio file with pyo, but when I try to run it, I get this message;
Traceback (most recent call last):
File "C:\Python27\pyotest.py", line 1, in
from pyo import *
File "C:\Python27\pyo.py", line 2, in
NameError: name 'Server' is not defined
My code:
from pyo import *
s = Server().boot()
s.start()
sf = SfPlayer("C:\Users\*****\Music\sound.mp3", speed=1, loop=True).out()
Looks like you have created the file C:\Python27\pyo.py. So instead of the actual pyo module getting imported, your file gets imported.
Rename the file C:\Python27\pyo.py and any pyc file (C:\Python27\pyo.pyc) associated with it and try again