這里的問題是我收到一條錯誤訊息:第 26 行,在init tk.Tk() 中。init (self, *args, **kwargs)。型別錯誤:create() 引數 1 必須是 str 或 None,而不是 App。在有人知道如何解決這個問題之前,我從未處理過這種錯誤嗎?
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)
uj5u.com熱心網友回復:
您的代碼中有幾個問題:
App應該繼承自tk.Tk而不是tk.Frametk.Tk().__init__(self, *args, **kwargs)應該是tk.Tk.__init__(self, *args, **kwargs),或者super().__init__(*args, **kwargs)tk.Frame.title('Simulator')應該self.title('Simulator')self.simulation = [Monkey(), Giraffe, Elephant()]應該是self.simulation = [Monkey(), Giraffe(), Elephant()],我想- 需要添加
from tkinter.messagebox import showinfo
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/350127.html
上一篇:洗掉輸入框
