from tkinter import *
from tkinter import filedialog
import shutil
import os
import os.path
path_directory = "C:\\"
def click_button():
os.remove(my_list.get(my_list.curselection()))
init_listbox()
def click_button_2():
source = path_directory + "\\"+my_list.get(my_list.curselection())
dest1 = "C:\\test"
shutil.move(source, dest1)
init_listbox()
def click_btndir():
global path_directory
e1.delete(0, 'end')
path_directory = filedialog.askdirectory()
e1.insert(0, path_directory)
init_listbox()
def init_listbox():
file_list = os.listdir(path_directory)
my_list.delete(0, END)
for fname in file_list:
my_list.insert(END, fname)
def select_listbox(evt):
path_label_2["text"] = my_list.get(my_list.curselection())
root= Tk()
root.geometry("680x500")
btndir = Button(root,text="выбрать папку", background="#555", foreground="#ccc", command=click_btndir)
btndir.pack(anchor=W,side="top")
dpath_label = Label(root,text="текущая директория", fg="#eee", bg="#333")
dpath_label.pack(anchor=W)
e1 = Entry(root)
e1.insert(0, "C:\\")
e1.pack(anchor=W,side="top")
navbar = Frame(root, bg="green", width=100)
navbar.pack(anchor=W,side=TOP)
my_list = Listbox(navbar,width=50,font=("Helvetica", 12))
init_listbox()
my_list.pack(fill="both",side="left")
my_list.bind('<<ListboxSelect>>', select_listbox)
scrollbar = Scrollbar(navbar)
scrollbar.config(command=my_list.yview)
scrollbar.pack(fill="y",side="left")
my_list.config(yscrollcommand=scrollbar.set)
path_label_1 = Label(root,text="имя выбранного файла", fg="#eee", bg="#333")
path_label_1.pack(anchor=W)
path_label_2 = Label(root,text="путь к файлу")
path_label_2.pack(anchor=W)
btn = Button(root,text="удалить файл", background="#555", foreground="#ccc", command=click_button)
btn.pack(anchor=W)
path_label_3 = Label(root,text="путь к хранилищу", fg="#eee", bg="#333")
path_label_3.pack(anchor=W)
e = Entry(root)
e.insert(0, "C:\\test")
e.pack(anchor=W)
btn2 = Button(root,text="переместить в хранилище", background="#555", foreground="#ccc", command=click_button_2)
btn2.pack(anchor=W)
root.mainloop()
|