【发布时间】:2018-04-29 18:49:11
【问题描述】:
我正在创建一个 GUI 来使用 tkinter 从网站下载文件。 但我遇到了一个意外的错误 代码:
from tkinter import *
from tkinter import ttk
import urllib.request
root = Tk(className='VideoDownloader')
root.geometry("400x200")
root.resizable(width=False, height=False)
Lab = ttk.Label(root, text='Download a file from any site')
Lab.grid(row=0, column=0)
def down():
u = url.get()
n = name.get()
urllib.request.urlretrieve(u, n)
Lab1 = ttk.Label(root, text='Enter file name :')
Lab1.grid(row=1, column=0)
name = ttk.Entry(root,)
name.grid(row=2, column=0)
Lab2 = ttk.Label(root, text='Enter video url :')
Lab2.grid(row=3, column=0)
url = Text(root,)
url.grid(row=4, column=0)
but = ttk.Button(root, text='Download', command=down())
but.grid(row=5, column=0)
root.mainloop()
产生错误:
Traceback (most recent call last):
File "C:/Users/User/Desktop/test.py", line 30, in <module>
but = ttk.Button(root, text='Download', command=down())
File "C:/Users/User/Desktop/test.py", line 14, in down
u = url.get()
TypeError: get() takes at least 2 positional arguments (1 given)
在我的上一个项目中,我创建了一个 GUI 来比较数字并且 get() 不需要参数
【问题讨论】:
-
url不是Entry。