I was writing a python GUI program with Spleeter. And when it comes to the Separation function, the error occurs. Here's my code:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from spleeter.separator import Separator
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
window = Tk()
screen_width,screen_height = window.maxsize()
window.title("Spleeter GUI Version")
w = int((screen_width-700)/2)
h = int((screen_height-400)/2)
window.geometry(f'700x400+{w}+{h}')
lbl = Label(window, text="File Path:")
lbl.grid(column=0, row=0)
txt = Entry(window, width=10)
txt.grid(column=1, row=0)
lbl2 = Label(window, text="Stems:")
lbl2.grid(column=0, row=1)
combo = Combobox(window)
combo['values'] = (2,4,5)
combo.current(0)
combo.grid(column=1, row=1)
def Separation():
File_name=txt.get();
stems='spleeter:'+combo.get()+'stems'
separator = Separator(stems)
separator.separate_to_file(File_name, 'out')
messagebox.showinfo("Notification", "Separation Finished!")
def clicked():
Separation()
btn = Button(window, text="Separate", command=clicked)
btn.grid(column=2, row=0)
def main():
window.mainloop()
if __name__=='__main__':
main()
And the error occurs every time I click on the Button, the message is like:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\MyUsrname\.conda\envs\music\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "d:\File\Code\python\helloworld.py", line 39, in clicked
Separation()
File "d:\File\Code\python\helloworld.py", line 33, in Separation
separator = Separator('spleeter:2stems')
File "C:\Users\MyUsrname\.conda\envs\music\lib\tkinter\ttk.py", line 1138, in __init__
Widget.__init__(self, master, "ttk::separator", kw)
File "C:\Users\MyUsrname\.conda\envs\music\lib\tkinter\ttk.py", line 559, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\Users\MyUsrname\.conda\envs\music\lib\tkinter\__init__.py", line 2292, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Users\MyUsrname\.conda\envs\music\lib\tkinter\__init__.py", line 2262, in _setup
self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk'
*) when importing something, You should either import what You need, e.g.from module import Class1, func_1, var_2and so on or import the whole module:import modulethen You can also use an alias:import module as mdor sth like that, the point is that don't import everything unless You actually know what You are doing; name clashes are the issue.