工具箱相关
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

movefileD_exe.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. try:
  51. str1 = ln.replace('\n','')
  52. except:
  53. str1 = ln
  54. #完整路径
  55. apath = inpath + '/' + str1
  56. #验证下路径是否存在
  57. if (os.path.exists(apath) == False):
  58. print(apath + ' not exist!')
  59. else:
  60. opath = outpath + '/' + str1
  61. #验证
  62. if (os.path.exists(opath) == True):
  63. print(opath + ' exist!')
  64. opath = outpath + '/' + str1 + '_CT'
  65. #复制
  66. shutil.move(apath,opath)
  67. messagebox.showinfo("消息","运行成功")
  68. window.destroy()
  69. tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
  70. tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
  71. tk.Button(window, text='选择', command=choose3).place(x=320, y=160, anchor='nw')
  72. tk.Button(window,text='确认',command=main).place(x=120,y=210,anchor='nw')
  73. tk.Button(window,text='取消',command=tuichu).place(x=220,y=210,anchor='nw')
  74. window.mainloop()
  75. if __name__ == '__main__':
  76. start()