Home > Blockchain >  line 26, in __init__ tk.Tk().__init__(self, *args, **kwargs). TypeError: create() argument 1 must be
line 26, in __init__ tk.Tk().__init__(self, *args, **kwargs). TypeError: create() argument 1 must be

Time:11-06

The problem here is that I get an error saying: line 26, in init tk.Tk().init(self, *args, **kwargs). TypeError: create() argument 1 must be str or None, not App. I have never dealt with this kind of error before does anyone know how to solve this?

import tkinter as tk
import tkinter.ttk as ttk
from x import Monkey, Giraffe, Elephant

Large_Font  = ("Verdana", 12)


class App(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Tk().__init__(self, *args, **kwargs)
        container = tk.Frame(self)

        container.pack(side='top',fill="both",expand = True)

        container.grid_rowconfigure(0, weight =1)
        container.grid_columnconfigure(0, weight = 1)

        self.simulation = []
        for row in range(5):
            self.simulation  = [Monkey(), Giraffe, Elephant()]

        tk.Frame.title('Simulator')
        self.geometry("800x800")
        self.resizable(False, False)

        self.label = ttk.Label(self, text='Sim',font=("Calibri",28,"bold"))


        self.label0 = ttk.Label(self,font=("Calibri",24,"bold"), text='Monkey')
        self.label1 = ttk.Label(self,font=("Calibri",24,"bold"), text='Giraffe')
        self.label2 = ttk.Label(self, text="Flat border", font=("Calibri",24,"bold"), relief="flat")

        self.label.pack(pady=10)
        self.label0.pack( pady=11,padx=10)
        self.label1.pack(pady=11,padx=11)
        self.label2.pack(pady=11)

        self.button = ttk.Button(self, text='Feed the Animals')
        self.button['command'] = self.button_clicked
        self.button.pack(pady=12)

    def button_clicked(self):
        showinfo(title='Information', message='Hello, Tkinter!')

# Press the green button in the gutter to run the script.
if __name__ == '__main__':

    App = App()
    App.mainloop()
    time_hours(5)

CodePudding user response:

There are few issues in your code:

  • App should be inherited from tk.Tk instead of tk.Frame
  • tk.Tk().__init__(self, *args, **kwargs) should be tk.Tk.__init__(self, *args, **kwargs), or super().__init__(*args, **kwargs)
  • tk.Frame.title('Simulator') should be self.title('Simulator')
  • self.simulation = [Monkey(), Giraffe, Elephant()] should be self.simulation = [Monkey(), Giraffe(), Elephant()], I think
  • need to add from tkinter.messagebox import showinfo
  • Related