我已经用Instaloader和Tkinter制作了一个insta profile图片下载器,但每当我点击下载按钮时,就会出现一些错误。下面是我的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中使用它时,它会显示上述错误
发布于 2020-07-22 22:39:00
问题是,您正在向mod.download_profile传递一个小部件,而它需要一个字符串。
您需要从entry小部件获取值,并将该值传递给函数,而不是传递小部件本身:
mod.download_profile(user_entry.get(), profile_pic_only=True)
^^^^^^https://stackoverflow.com/questions/63036365
复制相似问题