Answer the question
In order to leave comments, you need to log in
Error in tkinker when clicking on a button, how to fix?
Hello, I am making a program for a PC and I need to create a button in the program that will download the required file via requests on request. If I set a value through the checkbox for this function, then it endlessly starts to repeat the download. And through the button (button) the code goes into an error
eturn self.func(*args)
TypeError: save() missing 1 required positional argument: 'link'
def save(link):
filename = link.split('/')[-1]
print (filename)
r = requests.get(link)
open(filename, 'wb').write(r.content)
save(link1)
save_1 = tk.Label(win, text='Desktop cкачан в текущую папку', bg='#CCC', font=('Arial',10))
save_1.pack()
save_1.place(x=15, y=200)
download_dxbx_btn = tk.Button(win,command=save, text="Скачать Desktop")
download_dxbx_btn.pack()
download_dxbx_btn.place(x=17, y=150)
setup_dxbx_desktop = tk.StringVar()
setup_dxbx_desktop.set('Yes')
download_dxbx = tk.Checkbutton(text="Скачать Desktop",bg='#CCC', font=('Arial',12), variable=setup_dxbx_desktop, onvalue='Yes', offvalue='No')
download_dxbx.pack(anchor=W, padx=20)
Answer the question
In order to leave comments, you need to log in
inside the save function you call it again - why? and where link1 comes from is also not clear
def save(link):
filename = link.split('/')[-1]
print (filename)
r = requests.get(link)
open(filename, 'wb').write(r.content)
#save(link1) # убираем это
save_1 = tk.Label(win, text='Desktop cкачан в текущую папку', bg='#CCC', font=('Arial',10))
save_1.pack()
save_1.place(x=15, y=200)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question