AttributeError: 'int' object has no attribute 'pack'

AttributeError: 'int' object has no attribute 'pack'

所以,问题是,我目前正在尝试制作一个 minecraft tellraw 命令生成器。我还没有制作菜单,我正在尝试使用 TKinter 在 canvas 中显示图像。 canvas 确实显示,并且它确实有效。但是当我尝试使用函数“create_image”在其中打印图像时,当我尝试使用 pack 函数时出现此错误:

Traceback (most recent call last):
  File "C:\Users\PC\Desktop\Python\Algorithms\Minecraft Generator\index.py", line 34, in <module>
    MAIN_MENU_TELLRAW_IMAGE.pack()
AttributeError: 'int' object has no attribute 'pack'

这是我的代码:

from tkinter import *

# Window
window = Tk()
window.title('Minecraft Generator')
window.geometry("1080x600")
window.minsize(1080, 600)
window.maxsize(1080, 600)
window.iconbitmap('assets/img/logo.ico')

# Config
window.config(background='#627f1f')

#Composants

    # Main Menu Title
TITLE_FRAME = Frame(window, bg='#627f1f')
MAIN_MENU_TITLE = Label(TITLE_FRAME, text='Minecraft Generator' , font=("Courrier", 40), bg='#627f1f' , fg='white')
MAIN_MENU_SUBTITLE = Label(TITLE_FRAME, text='A Minecraft Generator for all needs !' , font=("Courrier", 15), bg='#627f1f' , fg='white')

    # Main Menu TellRaw
MAIN_MENU_TELLRAW_BUTTON = Button(TITLE_FRAME, text='Tellraw Command', bg='white' , fg='#627f1f' , font=("Courrier News", 15))
MAIN_MENU_TELLRAW_IMAGE = Canvas(window, width=157, height=100)
MAIN_MENU_TELLRAW_IMAGE = MAIN_MENU_TELLRAW_IMAGE.create_image((157, 100), image=PhotoImage(file='assets/img/tellraw_logo.png'))

# Packing

    # Title Frame
MAIN_MENU_TITLE.pack()
MAIN_MENU_SUBTITLE.pack()
TITLE_FRAME.pack(side='top')

    # TellRaw
MAIN_MENU_TELLRAW_BUTTON.pack(pady=25)
MAIN_MENU_TELLRAW_IMAGE.pack()

# Display Window
window.mainloop()

我真的不知道为什么会发生这个错误...如果有人能帮助我,那将是一种 ^^

正如@Andrea 所说:

<tkinter.Canvas>.create_image(...) returns 用于标识特定 canvas 项目(其 id)的 int。在行中:MAIN_MENU_TELLRAW_IMAGE = MAIN_MENU_TELLRAW_IMAGE.create_image(...)MAIN_MENU_TELLRAW_IMAGE 替换为 int。当您尝试 MAIN_MENU_TITLE.pack() 时,您正在尝试调用 int.pack() 方法,该方法不存在并引发错误