Tkinter delay a copy command over ssh (Paramiko)
Question: This script in Tkinter zip a file that reside in a linux server and then copy
the zipped file in the local machine. To do so, Paramiko first execute the zip
command in the server, then a new function is called that copy the file in the
local machine. However, while the zip is being created, the new file gets a
temporary name and only at the end of the zip procedure it gets the expected
name (compressed_file.zip in the example). The file is large and the zipè
procedure takes as much as ten seconds. The copy function return therefore an
error of "IOError No such file" because the file is present but still with a
temporary name.

I need to add a pause somehow, in a way that the copy function is delayed and
allows the first to be completed. I tried with **after** with no luck. I can
see from debugging that the copy_zip() is being executed without pausing for
10 seconds as I exepected.

(I cut all the logic that is not strictly needed to understand the problem)

    
    
    from Tkinter import *
    import ttk
    import paramiko
    from tkFileDialog import * 
    import os
    
    
    root = Tk()
    root.title("Extract file")
    root.geometry('200x400+200+200')
    root.resizable(width= FALSE, height= FALSE)
    
    
    def copy_file():
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        copy_command = ("zip compressed_file /log_folder/log.xml")
        client.connect(ip_server, username=user, password=psw)
        (stdin, stdout, stderr) = client.exec_command(copy_command)    
        root.after(10000, copy_zip())
    
    
    def copy_zip():
        remotepath = "/home/user/compressed_file.zip"
        localpath = "c:\python27\copied_file.zip"
        t = paramiko.Transport(comboserver)
        t.connect(username=user, password=psw)
        sftp = paramiko.SFTPClient.from_transport(t)
        sftp.get(remotepath, localpath)
        sftp.close
    
    main_container = Frame(root, bg="bisque")
    main_container.pack(side=TOP, fill="both", expand=False)
    
    top_frame = LabelFrame(main_container, text =" Get File ")
    top_frame.pack(side = TOP, fill = BOTH)
    
    t_go = Button(top_frame, text= "Go!", width =8, command = copy_file)
    t_go.pack(side = LEFT, padx = 15, pady = 20)
    
    mainloop()
    


Answer: You are using `after` incorrectly. `after` must be given a _reference_ to the
function but you are _calling_ the function and passing the result to _after_.

change your use of `after` to this:

    
    
    root.after(10000, copy_zip)
    

If you want to pass arguments to `copy_file`, include them as arguments to
`after`:

    
    
    root.after(10000, copy_zip, arg1, arg2, arg3)
    

