[Python] Tkinter Button Widget Error: Expected Integer but Got String 'Nerd'

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm encountering an error while trying to add a button widget to a Tkinter window in Python. Drawing a window to the screen works fine though.

    Traceback (most recent call last):
    File "/home/saif/new/c.py", line 11, in <module>
    button = tk.Button(root, text="Click Me", command=button_clicked)
    File "/usr/lib/python3.10/tkinter/__init__.py", line 2679, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
    File "/usr/lib/python3.10/tkinter/__init__.py", line 2601, in __init__
    self.tk.call(
    _tkinter.TclError: expected integer but got "Nerd"


    Here's the source code:

    import tkinter as tk

    # Create the main window
    root = tk.Tk()

    # Create a function to be called when the button is clicked
    def button_clicked():
    print("Button clicked!")

    # Create a button widget
    button = tk.Button(root, text="Click Me", command=button_clicked)
    button.pack()

    # Run the Tkinter event loop
    root.mainloop()


    General Overview:

    Python 3.10.12
    tk 0.1.0
    tk-tools 0.16.0
    Linux Mint 21.1 (Xorg)


    How can I avoid this issue?

    Continue reading...

Compartilhe esta Página