【发布时间】:2019-12-18 20:29:43
【问题描述】:
我在 nano pi 照片文件夹中有近 100 张图像。我正在使用paramiko 将这些图像传输到Windows 系统中。为此,我使用 Python 创建了一个 GUI,我想在其中选择文件夹和一个下载按钮。单击下载按钮后,它还应该更新进度条,因为所有图像都从 Linux 传输到 Windows。
# import librery for corresponding code
import os
import shutil
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
import paramiko
from scp import SCPClient
import time
import threading
# initialize gui interface
root=Tk()
root.geometry("510x200")
root.title("GEOTAG PICTURE MANEGER")
root.resizable(0,0)
root.configure(bg="#ac75c9")
root.wm_iconbitmap(r'D:\EdallSystem\NPNT_RELT\client.ico')
# select the folder that u want to select for past the pic
global folder_selected, path
def getFolderPath():
global folder_selected
folder_selected = filedialog.askdirectory()
#print(folder_selected)
folderPath.set(folder_selected)
folderPath = StringVar()
a = Label(root ,text="Chose Folder :")
#a.grid(row=0,column = 0)
a.place(x=20,y=50)
E = Entry(root,textvariable=folderPath,width="60")
E.grid(row=0,column=1)
E.place(x=100,y=50)
btnFind = ttk.Button(root, text="Browse Folder",command=lambda: background(getFolderPath, ()))
btnFind.grid(row=0,column=3)
btnFind.place(x=420,y=50)
# download the pic from root directory to the local system
# it will search the file from root path i.e remote_images_path = '/root/photo/photo/'
# and paste it to the local folder
def down():
try:
global folder_selected,path
files = []
remote_images_path = '/root/photo/photo/'
path=folder_selected
path=path.replace('/', '\\\\')+'\\\\'
#print(path)
local_path = path #"D:\\EdallSystem\\socket_pro\\photo\\folder_selected\\"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = "192.168.2.199", username = "root",password='fa')
ftp = ssh.open_sftp()
scp = SCPClient(ssh.get_transport())
for i in ftp.listdir(remote_images_path):
start = time.time()
#lstatout=str(ftp.lstat(i)).split()[0]
#if 'd' in lstatout:
#print (i, 'is a directory')
files.append(i)
for file in files:
file_remote = remote_images_path + file
file_local = local_path + file
print (file_remote + '>>>'*2 + file_local)
scp.get(file_remote, file_local)
done = time.time()
elapsed = done - start
print("Time taken in Sec:",elapsed)
scp.close()
ssh.close()
except:
messagebox.showinfo(" ", "No Picture Selected")
#ttk.level(root,text='No pic')
def background(func, args):
th = threading.Thread(target=func, args=args)
th.start()
dwn=ttk.Button(root,text="Download",width='25',command=lambda: background(down, ()))
dwn.place(x=190,y=120)
root.mainloop()
我想在 GUI 中添加一个进度条,但我不知道怎么做。请帮帮我。
【问题讨论】:
-
@Nick 谢谢你的努力。请帮助我,我想学习新的想法。