Python-AttributeError,同时将对象作为类参数传递
这是我关于StackOverflow的第一个问题 我正在尝试使用MVC架构用GUI做简单的游戏。 我按设想编写代码,但是: AttributeError:“控制器”对象没有属性“视图” 我已经检查了我跟踪的代码和yt视频, 我还没有在其他Stackoverflow帖子上找到相关的回应,所以我坚持进行调试 我是新手(第一次将对象作为属性传递到类中),您能帮助我修复它吗Python-AttributeError,同时将对象作为类参数传递,python,class,object,parameters,Python,Class,Object,Parameters,这是我关于StackOverflow的第一个问题 我正在尝试使用MVC架构用GUI做简单的游戏。 我按设想编写代码,但是: AttributeError:“控制器”对象没有属性“视图” 我已经检查了我跟踪的代码和yt视频, 我还没有在其他Stackoverflow帖子上找到相关的回应,所以我坚持进行调试 我是新手(第一次将对象作为属性传递到类中),您能帮助我修复它吗 from ST_model import Model from ST_view import View class Contro
from ST_model import Model
from ST_view import View
class Controller:
def __init__(self):
self.model = Model()
self.view = View(self)
def main(self):
#it starts mainloop()
self.view.main()
def find_data_for_creature_slotz(self):
result = self.model.creature_data()
#where is the issue? :( oups
self.view.slot1_description.set(result[0])
self.view.slot1_photo.set(result[1])
self.view.slot2_description.set(result[2])
self.view.slot2_photo.set(result[3])
self.view.slot3_description.set(result[4])
self.view.slot3_photo.set(result[5])
self.view.slot4_description.set(result[6])
self.view.slot4_photo.set(result[7])
self.view.slot5_description.set(result[8])
self.view.slot5_photo.set(result[9])
self.view.slot6_description.set(result[10])
self.view.slot6_photo.set(result[11])
和顶部零件表单ST_view.py:
import tkinter as tk
from tkinter import ttk
from PIL import ImageTk, Image
class View(tk.Tk):
PAD = 5
def __init__(self, controller):
super().__init__()
self.controller = controller
self.title("StarCraft Tournament")
self.iconbitmap(r"terran_icon.ico")
#self.value_var = tk.StringVar()
self.slot1_description = tk.StringVar()
self.slot1_photo = tk.StringVar()
self.slot2_description = tk.StringVar()
self.slot2_photo = tk.StringVar()
self.slot3_description = tk.StringVar()
self.slot3_photo = tk.StringVar()
self.slot4_description = tk.StringVar()
self.slot4_photo = tk.StringVar()
self.slot5_description = tk.StringVar()
self.slot5_photo = tk.StringVar()
self.slot6_description = tk.StringVar()
self.slot6_photo = tk.StringVar()
self._make_main_frame()
self._make_architecture()
self._make_Creature_frame_for_players()
self._fill_creature_slotz()
当您定义
self.view
时,以及当您遇到错误时,问问自己。哪一个先来?不幸的是我不明白#布莱恩·奥克利可以在示例中展示它吗?这很方便。我正在继续我的程序,最近遇到了类似的问题:_tkinter.tkapp'对象没有属性'slot1\u photo\u label'。请在定义self.view
时以及出现错误时问问自己。哪一个先来?不幸的是我不明白#布莱恩·奥克利可以在示例中展示它吗?这很方便。我正在推进我的程序,最近遇到了类似的问题:\u tkinter.tkapp'对象没有属性'slot1\u photo\u label'