工具箱相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

copyfileD_exe.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import os
  2. import tkinter as tk
  3. import numpy as np
  4. from tkinter import filedialog as tkFileDialog
  5. from tkinter import messagebox
  6. import shutil
  7. def start():
  8. window = tk.Tk() # 创建窗口对象的背景色
  9. window.title('复制文件程序') # 设置窗口的标题
  10. window.geometry('400x250') # 设置窗口的大小
  11. title = tk.Label(window, text='复制文件程序',
  12. font=('微软雅黑', 12), width=40, height=3)
  13. title.place(x=0, y=0, anchor='nw')
  14. choosepath = tk.Label(window, text='选择源文件夹:',
  15. font=('微软雅黑', 12), width=20, height=2)
  16. choosepath.place(x=0, y=50, anchor='nw')
  17. path_var1 = tk.StringVar() # 输入路径
  18. entry1 = tk.Entry(window, textvariable=path_var1)
  19. entry1.place(x=170, y=65, anchor='nw')
  20. txtpath = tk.Label(window, text='选择txt:',
  21. font=('微软雅黑', 12), width=20, height=2)
  22. txtpath.place(x=0, y=100, anchor='nw')
  23. path_var2 = tk.StringVar() # 输入路径
  24. entry2 = tk.Entry(window, textvariable=path_var2)
  25. entry2.place(x=170, y=115, anchor='nw')
  26. resultpath = tk.Label(window, text='输出文件夹:',
  27. font=('微软雅黑', 12), width=20, height=2)
  28. resultpath.place(x=0, y=150, anchor='nw')
  29. path_var6 = tk.StringVar() # 输出路径
  30. entry6 = tk.Entry(window, textvariable=path_var6)
  31. entry6.place(x=170, y=165, anchor='nw')
  32. def choose2():
  33. file_dir2 = tkFileDialog.askopenfilename(filetypes=[('TEXT', '*.txt'),('All Files', '*')])
  34. path_var2.set(file_dir2)
  35. def choose1():
  36. file_dir1 = tkFileDialog.askdirectory()
  37. path_var1.set(file_dir1)
  38. def choose3():
  39. file_dir6 = tkFileDialog.askdirectory()
  40. path_var6.set(file_dir6)
  41. def tuichu():
  42. window.destroy()
  43. def main():
  44. inpath = entry1.get()
  45. txtpath = entry2.get()
  46. outpath = entry6.get()
  47. #读取txt
  48. with open(txtpath,'r') as filer:
  49. for ln in filer:
  50. str1 = ln.replace('\n','')
  51. #完整路径
  52. apath = inpath + '/' + str1
  53. #验证下路径是否存在
  54. if (os.path.exists(apath) == False):
  55. print(apath + ' not exist!')
  56. else:
  57. opath = outpath + '/' + str1
  58. #验证
  59. if (os.path.exists(opath) == True):
  60. print(opath + ' exist!')
  61. opath = outpath + '/' + str1 + '_CT'
  62. #复制
  63. shutil.copytree(apath,opath)
  64. messagebox.showinfo("消息","运行成功")
  65. window.destroy()
  66. tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
  67. tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
  68. tk.Button(window, text='选择', command=choose3).place(x=320, y=160, anchor='nw')
  69. tk.Button(window,text='确认',command=main).place(x=120,y=210,anchor='nw')
  70. tk.Button(window,text='取消',command=tuichu).place(x=220,y=210,anchor='nw')
  71. window.mainloop()
  72. if __name__ == '__main__':
  73. start()