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 fromtk.Tk
instead oftk.Frame
tk.Tk().__init__(self, *args, **kwargs)
should betk.Tk.__init__(self, *args, **kwargs)
, orsuper().__init__(*args, **kwargs)
tk.Frame.title('Simulator')
should beself.title('Simulator')
self.simulation = [Monkey(), Giraffe, Elephant()]
should beself.simulation = [Monkey(), Giraffe(), Elephant()]
, I think- need to add
from tkinter.messagebox import showinfo