V
V
vadimeasy2021-11-12 07:54:58
Python
vadimeasy, 2021-11-12 07:54:58

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'

here is the function:
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)


Here is the download button:
download_dxbx_btn = tk.Button(win,command=save, text="Скачать Desktop")
download_dxbx_btn.pack()
download_dxbx_btn.place(x=17, y=150)


Here is the checkbox:
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

1 answer(s)
A
Alexander, 2021-11-12
@vadimeasy

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)

what is there about the checkbox is not clear, you need the full code of the program

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question