【发布时间】:2017-06-17 10:04:14
【问题描述】:
class Video:
def __init__(self):
self.v1 = StringVar()
self.entry1 = Entry(root, textvariable=v1)
self.entry1.pack()
self.downloadUrl = v1.get()
def downloadVideo(self):
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
self.ydl.download([self.downloadUrl])
menu = Menu(root)
root.config(menu=menu)
menuOne = Menu(menu, tearoff=0)
menu.add_cascade(label='Magrobebi', menu=menuOne)
menuOne.add_command(label='Download Video', command=Video.downloadVideo)
我正在尝试在菜单中创建一个用于下载视频的按钮。我在传递该 downloadUrl 时遇到了麻烦,因为它不是全局变量。 我不能将命令本身放在类中,因为它甚至不会以这种方式创建。目前,“TypeError: downloadVideo() missing 1 required positional argument: 'self'”是我一直遇到的错误,我不能在这个类中调用另一个类的函数,我该如何解决这个问题?我只想有一个按钮来创建一个条目,用户可以在其中输入链接并下载它。
【问题讨论】:
-
您的 downloadVideo 方法不是静态的。您必须将其设为静态(方法上方的@staticmethod)或实例化该类的实例。