无法使用 Instaloader 和 tkinter 下载图像

cant download the image with Instaloader and tkinter

我使用 Instaloader 和 Tkinter 制作了一个 insta 个人资料图片下载器,但每当我单击下载按钮时,都会出现一些错误。 下面是我的 Tkinter 代码:

import instaloader
import tkinter as tk

root = tk.Tk()
root.title("profile Pic Downloader")
root.geometry("300x200")

user_var = tk.StringVar()

def download():
    mod = instaloader.Instaloader()
    mod.download_profile(user_entry, profile_pic_only=True)


user_label = tk.Label(root, text = 'Enter Insta Id: ', font=('calibre', 10, 'bold'))
user_entry = tk.Entry(root, textvariable = user_var, font=('calibre',10,'normal'))

download_button = tk.Button(root, text = 'Download', command = download)

user_label.grid(row=0,column=0)
user_entry.grid(row=0,column=1)
download_button.grid(row=1,column=1)

root.mainloop()

这是我的错误日志:

$ C:/Users/hp/AppData/Local/Programs/Python/Python38/python.exe g:/InstaDownloader/InstaPPDownloader.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__     
    return self.func(*args)
  File "g:/InstaDownloader/InstaPPDownloader.py", line 12, in download
    mod.download_profile(user_entry, profile_pic_only=True)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\instaloader\instaloader.py", line 1156, in download_profile
    profile_name = profile.username
AttributeError: 'Entry' object has no attribute 'username'

仅使用 instaloader,一切正常,如下代码正常:

import instaloader

mod = instaloader.Instaloader()
d = input("Enter Instagram username: ")
mod.download_profile(d, profile_pic_only=True)

但是当我将它与 tkinter 一起使用时,它显示了上述错误

问题是您将小部件传递给 mod.download_profile,它需要一个字符串。

您需要从条目小部件获取值,并将该值传递给函数而不是传递小部件本身:

mod.download_profile(user_entry.get(), profile_pic_only=True)
                               ^^^^^^