Hi There.

My code is functioning well these days ... my first project which is a big project is nearing completion and would like some ways of tidying up some functions.

It's a backup program and when you press a button it backs up a section of your system. Here is the current code for the press button part.

def picbackup():
    source = ['-ir!"%USERPROFILE%\*.bmp"', '-ir!"%USERPROFILE%\*.tif"', '-ir!"%USERPROFILE%\*.jpg"', '-ir!"%USERPROFILE%\\*.gif"']
    target_dir = '.\\'
    today = time.strftime('%d_%m_%Y')
    target = '.\\Backup\Pictures_' + today + '.zip'
    zip = os.popen ("D:\\Backup\\7Zip\\7z.exe a -bd -ssw {0} {1}".format(target, ' '.join(source)))
    shellOutput = zip.read()
    zip.close()
    outputWindow.delete('1.0',END)
    outputWindow.insert('1.0',shellOutput)
    if os.system(zip_command) == 0:
        print('Successful backup to', target)
    else:
        print('Backup FAILED')

There is a reference to an output window but it doesn't update till the end and to be honest, i don't need it to and infact even happy to get rid of it, it is just how the code looks today.

So what i'm looking for is a hopefully a much easier solution, replace the output window, but all my research findings seem to point to others looking for "live update of their dos command in a window" whereas i think a more simple solution would be a popup that say "please wait ..." and maybe a small animation to show it is working (i have an anim i would love to use).... once the process is complete, it either disappears by itself OR a small "ok" button can appear which you can click and close this function and back at the main menu. Since i can't find anyone else who has done something like this, i'm not sure quite how to go about this and would love some advice if anyone has any.

Thankyou.

I could give you a full example written for wxPython, but not for Tkinter, sorry :P

But regardless, you'll probably need to use threading for this, as your program will stall until the zip command is complete (I think?...) before continuing along with the rest of the script.
If that IS the case, then you can create a thread to run the zip command, and another to handle the message dialog and the updating of it. Otherwise, the subprocess module may be what you're looking for to run the zip command with.

Secondly, there should be some sort of dialog class in Tk like there is in wxPython. Something that holds the focus of the program so that the parent window can't be accessed until the pop-up is destroyed. I have never used Tk so I don't know if this code will be helpful to you, but this may be what you're looking for:
http://www.java2s.com/Code/Python/GUI-Tk/Customizeddialog.htm

I don't know if that will maintain the program's focus on the dialog though. wxPython dialogs have the ShowModal() method to do this... I assume Tk has an equivalent.

Sorry I can't be more specific!

All sounds familar with another things i was doing where a window needed to hold focus, while i kept getting it to work in some way, it broke something else and i never quite got it running, and my end solution was to scrap it and come up with a new design that solved my problem well.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.