我有以下文件上传代码。我想为两件事修改这段代码: 1.如果用户取消 askopenfilenames 命令,整个程序将停止。2.如果用户没有选择所需的文件数,文件上传功能将重新启动,直到选择正确的文件数。
import Tkinter
from Tkinter import Tk
tk=Tk()
from tkFileDialog import askopenfilenames
import tkMessageBox
def fileupload():
tk.withdraw()
uploadedfiles = askopenfilenames(multiple=True)
##if user cancels: (IF STATEMENT TO RESULT IN MESSAGEBOX AND CODE TO STOP)
###tk.withdraw()
###tkMessageBox.showinfo(message="File Upload has been cancelled program will stop")
##Stop code
if len(uploadedfiles)>2 or len(uploadedfiles)<2:
tk.withdraw()
tkMessageBox.showinfo(message="2 files have not been selected!")
##rerun function to reselect files
return uploadedfiles
uploadedfiles=fileupload()
print uploadedfiles