[Python] I continue to get the error: " TypeError: 'str' object is not callable " when...

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    This is what I currently have. Whenever I press the button at the bottom, it gets the error and the window stays blank. The error also says

    tennis_window = Toplevel()
    File "C:\Python27\lib\lib-tk\Tkinter.py", line 2136, in __init__self.title(root.title())


    which I don't understand, also apologies, this is my first post so please let me know if i can clarify anything

    #Create the main window
    Main_Window = Tk()

    #Main window title
    Main_Window.title = ('Top Ten')

    #Converting to photo image
    Top_Ten_Pic = gif_to_PhotoImage(urlopen('random gif image url').read())

    #Converting to photo image
    Tennis_pic = (urlopen('random gif image url').read())


    #Create a label to display the downloaded image
    top_ten_label = Label(Main_Window, image = Top_Ten_Pic, height = 280,
    width = 400)
    top_ten_label.grid(row=0,column=0, columnspan = 3)

    #command for top ten tennis window
    def button_tennis():

    #new toplevel window
    tennis_window = Toplevel()

    #title the window
    tennis_window.title = ('Top Ten Tennis')


    #Create a label to display the downloaded image
    top_ten_label = Label(tennis_window, image = Tennis_pic, height = 280,
    width = 400)
    top_ten_label.grid(row=0,column=0, columnspan = 3)

    #start the windows event loop
    top_tennis.mainloop()

    #Top ten tennis button (mainwindow)
    tennis_button = Button(Main_Window, text = 'Top Ten Tennis', font =
    ('Times New Roman', 12), command = button_tennis)
    tennis_button.grid(row = 1, column = 0)


    Main_Window.mainloop()

    Continue reading...

Compartilhe esta Página