Error "'str' object is not callable" when using simpledialog.askstring()

56 views Asked by At

My code:


class Punkty_Edycja_Frame(ttk.Frame):
    def __init__(self, parent):
        super().__init__(parent)
        self.grid(row = 1, column = 0, sticky='nesw')
        self.rowconfigure((0, 1, 2), weight=1, uniform='a')
        self.columnconfigure((0, 1), weight=1, uniform='a')
        
        self.punkty_listbox = tk.Listbox()
        self.punkty = {}
        
        #zapisanie punktu
        ttk.Button(self, text = "Zapisz punkt", command = self.zapisz_punkt
                   ).grid(row = 0, column = 0, sticky='nesw')
        
    def pobierz_zmienne_q(self):
        return (0, 0, 0, 0, 0, 0)

    def zapisz_punkt(self):
        nazwa = sd.askstring('T', "Wpisz nazwę punktu:")
        if nazwa != '' and nazwa != None:
            self.punkty_listbox.insert(tk.END, nazwa)
            self.punkty[nazwa] = self.pobierz_zmienne_q()
        print(self.punkty)

I'm getting

TypeError: 'str' object is not callable"

specifically on the line nazwa = sd.askstring('T', "Wpisz nazwę punktu:") of zapisz_punkt() method. I don't know why.

Variable nazwa should give me a string from the pop-up window. I made sure I imported simpledialog it correctly. Other modules such as messagebox and filedialog work (on other buttons). Even if I call it inside __init__ method I get this error. I have no Idea where am I calling this string.

Here's the full stack trace of the error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "c:\users\me\desktop\aplikacja gui\pusty.py", line 230, in zapisz_punkt
    nazwa = sd.askstring('T', "Wpisz nazwę punktu:")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\tkinter\simpledialog.py", line 411, in askstring
    d = _QueryString(title, prompt, **kw)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\tkinter\simpledialog.py", line 388, in __init__
    _QueryDialog.__init__(self, *args, **kw)
  File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\tkinter\simpledialog.py", line 283, in __init__
    Dialog.__init__(self, parent, title)
  File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\tkinter\simpledialog.py", line 109, in __init__
    Toplevel.__init__(self, master)
  File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 2700, in __init__
    self.title(root.title())
               ^^^^^^^^^^^^
TypeError: 'str' object is not callable
0

There are 0 answers