#!/usr/bin/python#-*-coding:utf-8-*-#Filename:backUp.py#Import TemplateImportTkinterImportOSImport Time#define functions, here's the essence.defbackup ():GlobalEntry_sourceGlobalEntry_target Source=entry_source.get () Target_dir=entry_target.get () Today_dir= Target_dir + time.strftime ('%y%m%d') Time_dir= Time.strftime ("%h%m%s") Touch= Today_dir + os.sep + time_dir +'. zip'Command_touch="ZIP-QR"+ Touch +' '+SourcePrintCommand_touchPrintSourcePrintTarget_dirifOs.path.exists (today_dir) = =0:os.mkdir (Today_dir)ifOs.system (command_touch) = =0:Print 'Success backup up' Else: Print 'Failed Backup'#Initialize the window and set the caption and sizeRoot =tkinter.tk () root.title ('BackUp') Root.geometry ("200x200")#label为文本框, entry is the input box, grid () is the display functionLbl_source = Tkinter.label (Root, text='Source') Lbl_source.grid (Row=0, column=0) Entry_source=tkinter.entry (Root) entry_source.grid (row=0,column=1)#two controls in the second rowLbl_target = Tkinter.label (Root, text='Target') Lbl_target.grid (Row=1, column=0) Entry_target=tkinter.entry (Root) entry_target.grid (row=1,column=1)#a button control on the third rowBut_back = Tkinter.button (root,text='BackUp') But_back.grid (Row=3, column=0) but_back["Command"] =Backup#the beginning of the interfaceRoot.mainloop ()
Python Backup Script