1

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'
1
  • You probably need to add a master? not a string as the error shows you have added. Also you have got another problem that is prone to cause issues because you import everything: I strongly advise against using wildcard (*) when importing something, You should either import what You need, e.g. from module import Class1, func_1, var_2 and so on or import the whole module: import module then You can also use an alias: import module as md or sth like that, the point is that don't import everything unless You actually know what You are doing; name clashes are the issue. Commented Aug 12, 2021 at 8:39

1 Answer 1

1
separator = Separator(stems)

I assume you meant spleeter.separator.Separator (from [GitHub]: deezer/spleeter - Spleeter).

But (according to traceback), you ended up using [Python.Docs]: tkinter.ttk.Separator. And, that's due to (order is important too):

from spleeter.separator import Separator
# ...
from tkinter.ttk import *  # !!! THIS IS THE ONE !!!

Note that importing everything from a module is generally considered bad practice (with few exceptions, I personally consider that people using it kind of don't know what they are doing), so don't do it unless you know what it does behind the scenes.

Besides reusability and structure, packages and modules also act as (nested) namespaces, avoiding name clashes. So (most times), only import the package (or the module), and refer to classes, functions as (package.)module.function_or_class_or_variable_name

Example:

from spleeter import separator
sep = separator.Separator("a:b:c:d")

from tkinter import ttk
lbl = ttk.Label(window)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.