如何使用python在tkinter中添加进度条
我在nano-pi照片文件夹中有近100张图片。我正在使用如何使用python在tkinter中添加进度条,python,tkinter,Python,Tkinter,我在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
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中添加一个进度条,但不知道如何添加。请帮助我。查看Tkinter进度条上的这段代码
# importing tkinter module
from tkinter import *
from tkinter.ttk import *
# creating tkinter window
root = Tk()
# Progress bar widget
progress = Progressbar(root, orient = HORIZONTAL,
length = 100, mode = 'determinate')
# Function responsible for the updation
# of the progress bar value
def bar():
import time
progress['value'] = 20
root.update_idletasks()
time.sleep(1)
progress['value'] = 40
root.update_idletasks()
time.sleep(1)
progress['value'] = 50
root.update_idletasks()
time.sleep(1)
progress['value'] = 60
root.update_idletasks()
time.sleep(1)
progress['value'] = 80
root.update_idletasks()
time.sleep(1)
progress['value'] = 100
progress.pack(pady = 10)
# This button will initialize
# the progress bar
Button(root, text = 'Start', command = bar).pack(pady = 10)
mainloop()
@尼克:谢谢你的努力。请帮助我,我想学习新思维。