from tkinter import *
from tkinter import filedialog
import shutil
import os
import os.path
path_directory = "C:/"
path_directory_2 = "C:/"
source = ""
def click_rbutton():
global source,path_directory,path_directory_2
dest1 = path_directory_2 +"/" + os.path.basename(source)
if dest1[3] == '/':
dest1 = dest1[0:3:1] + dest1[4:len(dest1):1]
print(source)
print(dest1)
shutil.move(source,dest1)
init_listbox()
init_listbox_2()
def click_lbutton():
print ("hello")
def click_delete():
os.remove(my_list.get(my_list.curselection()))
init_listbox()
def click_delete_2():
os.remove(my_list_2.get(my_list_2.curselection()))
init_listbox_2()
def click_btndir():
global path_directory
e1.delete(0, 'end')
path_directory = filedialog.askdirectory()
e1.insert(0, path_directory)
init_listbox()
def click_btndir_2():
global path_directory_2
e1_2.delete(0, 'end')
path_directory_2 = filedialog.askdirectory()
e1_2.insert(0, path_directory_2)
init_listbox_2()
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 init_listbox_2():
file_list = os.listdir(path_directory_2)
my_list_2.delete(0, END)
for fname in file_list:
my_list_2.insert(END, fname)
def select_listbox(evt):
global path_directory,source
path_label_2["text"] = my_list.get(my_list.curselection())
source = path_directory + "/"+ my_list.get(my_list.curselection())
if source[3] == '/':
source = source[0:3:1] + source[4:len(source):1]
def select_listbox_2(evt):
path_label_2_2["text"] = my_list_2.get(my_list_2.curselection())
root= Tk()
root.geometry("1100x500")
btndir = Button(root,text="выбрать папку", background="#555", foreground="#ccc", command=click_btndir)
btndir.place(x = 0 , y = 0)
dpath_label = Label(root,text="текущая директория", fg="#eee", bg="#333")
dpath_label.place(x = 0, y = 30)
e1 = Entry(root)
e1.insert(0, "C:\\")
e1.place(x = 0, y = 50)
navbar1 = Frame(root, bg="green", width=100)
navbar1.place(x = 0 , y = 80)
my_list = Listbox(navbar1,width=50,font=("Helvetica", 12))
init_listbox()
my_list.pack(fill="both",side="left")
my_list.bind('<<ListboxSelect>>', select_listbox)
scrollbar = Scrollbar(navbar1)
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.place(x = 0, y = 300)
path_label_2 = Label(root,text="путь к файлу")
path_label_2.place(x = 0 , y = 330)
btn = Button(root,text="удалить файл", background="#555", foreground="#ccc", command=click_delete)
btn.place(x = 0 , y = 360)
#второй лситбокс
btndir_2 = Button(root,text="выбрать папку", background="#555", foreground="#ccc", command=click_btndir_2)
btndir_2.place(x = 600 , y = 0)
dpath_label_2 = Label(root,text="текущая директория", fg="#eee", bg="#333")
dpath_label_2.place(x = 600, y = 30)
e1_2 = Entry(root)
e1_2.insert(0, "C:\\")
e1_2.place(x = 600, y = 50)
navbar2 = Frame(root, bg="green", width=100)
navbar2.place(x = 600 , y = 80)
my_list_2 = Listbox(navbar2,width=50,font=("Helvetica", 12))
init_listbox_2()
my_list_2.pack(fill="both",side="left")
my_list_2.bind('<<ListboxSelect>>', select_listbox_2)
scrollbar2 = Scrollbar(navbar2)
scrollbar2.config(command=my_list_2.yview)
scrollbar2.pack(fill="y",side="left")
my_list_2.config(yscrollcommand=scrollbar2.set)
path_label_1_2 = Label(root,text="имя выбранного файла", fg="#eee", bg="#333")
path_label_1_2.place(x = 600, y = 300)
path_label_2_2 = Label(root,text="путь к файлу")
path_label_2_2.place(x = 600 , y = 330)
btn_2 = Button(root,text="удалить файл", background="#555", foreground="#ccc", command=click_delete_2)
btn_2.place(x = 600 , y = 360)
#второй лситбокс
rbutton = Button(root,text=">>>>>", background="#555", foreground="#ccc", command=click_rbutton)
rbutton.place(x = 500 , y = 150)
lbutton = Button(root,text="<<<<<", background="#555", foreground="#ccc", command=click_lbutton)
lbutton.place(x = 500 , y = 200)
root.mainloop()
|