1

I'm trying to add items to the combobox in GUIzero getting the value from a textbox when a button is pressed, but when the button is pressed I get the following error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Alfonso\AppData\Local\Programs\Python\Python313\Lib\tkinter\__init__.py", line 2068, in __call__
    return self.func(*args)
           ~~~~~~~~~^^^^^^^
  File "C:\Users\Alfonso\AppData\Local\Programs\Python\Python313\Lib\site-packages\guizero\PushButton.py", line 206, in _command_callback
    self._command()
    ~~~~~~~~~~~~~^^
TypeError: 'str' object is not callable

this is the part of my code that it is giving my issues:

from guizero import App, Box, Text, PushButton, ListBox, Window, TextBox, Combo

def add_team():
    n = t_names.value
    l_team.append(n)
    
def edit_menu():
    edit_win.show(wait=True)
    
app = App(title = "Timer", layout = "grid", bg="Gray")
bot = PushButton(app, text="edit", grid=[0,0], command="edit_menu")

edit_win = Window(app, title="Edit", layout="grid", bg="Gray")              #edit window
team_name = Text(edit_win, grid=[0,0], text="Teams:", size=30)
l_team = Combo(edit_win, options=[" "], grid=[1,0])
l_team.text_size=30
t_names = TextBox(edit_win, grid=[2,0], width=40)
mas_team = PushButton(edit_win, grid=[3,0], text="Add", command="add_team")
menos_team = PushButton(edit_win, grid=[4,0], text="Del", command="del_team")
edit_win.tk.state("zoomed")
edit_win.hide()

I think that I have a problem with my Tkinter library.

2
  • 2
    You are passing a string to the command args of your buttons instead of passing the function you want to call. That will lead to the error as strings are not callable. Commented Oct 16 at 7:59
  • command=edit_menu without " " - and this how you send functions in GUIs and in many other situations. Commented Oct 19 at 2:09

1 Answer 1

1

The problem originates from this line of code:

bot = PushButton(app, text="edit", grid=[0,0], command="edit_menu")

"edit_menu" is a string, so when you click the button the code tries to call the string rather than a function with the name in the string. It's no different then if you wrote code that looks like "edit_menu"().

When defining commands, you must define it with an actual command. Since the command is edit_menu, that's what you set the command option to:

bot = PushButton(app, text="edit", grid=[0,0], command=edit_menu)

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.