[Python] Tkinter Toplevel TypeError

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a new TopLevel through a button command, however, I am having some difficulty. With the following code:

    initial_state_button = Button(current_state, text=current_state_text, command = partial(initial_state_display, aatsplusv))
    initial_state_button.pack(side = TOP)

    ....

    def initial_state_display(dictionary):

    top = Toplevel()
    top.title = "About this State:"

    count = 0
    for key, value in dictionary["initial states"].iteritems():
    proposition = Message(top, text = key)
    proposition.grid(row=count, column=0, padx=5, pady=5)
    colon = Message(top, text = " : ")
    colon.grid(row=count, column=1, padx=5, pady=5)
    boolean = Message(top, text = str(value))
    colon.grid(row=count, column=2, padx=5, pady=5)
    count += 1


    I receive the following error:

    Exception in Tkinter callback
    Traceback (most recent call last):
    File "C:\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call__ return self.func(*args)
    File "Assignmentest.py", line 400, in initial_state_display top = Toplevel()
    File "C:\Python27\lib\lib-tk\Tkinter.py", line 2136, in __init__ self.title(root.title())
    TypeError: 'str' object is not callable


    I have no clue what is wrong. top = Toplevel is written exactly how the effbot example shows. Is toplevel not available in Python 2.7? If so, is there an 2.7 equivalent?

    Continue reading...

Compartilhe esta Página