I am writing a small app to copy some files. I have made almost everything that I wanted but 3 things:
1) Progress-bar to move while the copy option is in motion. I can display it but it won't react.
I am using this to show it:
self.p = ttk.Progressbar(self, orient=HORIZONTAL, length=300, mode='indeterminate')
self.p.grid(row=5)
and then to initiate it in another def which is called upon a press of the button:
self.p.start()
shutil.copytree(self.source_direcotry0, self.cam0)
shutil.copytree(self.source_direcotry1, self.cam1)
shutil.copytree(self.source_direcotry2, self.cam2)
self.p.stop()
Unfortunately the copying occurs but the bar doesn't move at all.
2) Second problem is connected to the information bar that I am displaying at the bottom of the app window:
self.status = Label(self.master, text="Waiting for process to start...", bd=1, relief=SUNKEN, anchor=W)
self.status.pack(side=BOTTOM, fill=X)
And then when the same copying def is called at the beginning of it I have this:
self.status['text'] = "Files are being copyied, have patience ;)".format(self.status)
And the status is not changed which is weird as at the end of this def I also have same command to change the status and this one works:
self.status['text'] = "Files have been copyied".format(self.status)
3) I can't seem to attach a picture I have checked all kinds of different options and none of them seem to work, the one presented here seems like tries to display something (the window gets bigger) but the picture is not visible:
self.img = ImageTk.PhotoImage(Image.open("az.png"))
self.panel = Label(self, image=self.img, bg="#E6E6E6")
self.display = self.img
self.panel.grid(row=8)
I am a bit unsure why it is happening like that, just in case and also for more info I am posting here the complete code:
from tkinter import *
from tkinter import ttk
import re
from tkinter import messagebox
from tkinter import filedialog
import ntpath
import os
import shutil
import tkinter.filedialog as fdialog
from send2trash import send2trash
from PIL import Image, ImageTk
#os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
# Here, we are creating our class, Window, and inheriting from the Frame
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
class Window(Frame):
# Define settings upon initialization. Here you can specify
def __init__(self, master=None):
# parameters that you want to send through the Frame class.
Frame.__init__(self, master, bg="#E6E6E6")
#reference to the master widget, which is the tk window
self.master = master
#with that, we want to then run init_window, which doesn't yet exist
self.init_window()
def copyy(self):
self.status['text'] = "Files are being copyied, have patience ;)".format(self.status)
self.source_direcotry0= '/Volumes/CAM0/DCIM/100HDDVR'
self.source_direcotry1= '/Volumes/CAM1/DCIM/100HDDVR'
self.source_direcotry2= '/Volumes/CAM2/DCIM/100HDDVR'
self.source_direcotry3= '/Volumes/CAM3/DCIM/100HDDVR'
self.source_direcotry4= '/Volumes/CAM4/DCIM/100HDDVR'
self.source_direcotry5= '/Volumes/CAM5/DCIM/100HDDVR'
self.source_direcotry6= '/Volumes/CAM6/DCIM/100HDDVR'
self.source_direcotry7= '/Volumes/CAM7/DCIM/100HDDVR'
self.source_direcotry8= '/Volumes/CAM8/DCIM/100HDDVR'
self.source_direcotry9= '/Volumes/CAM9/DCIM/100HDDVR'
self.source_direcotry10= '/Volumes/CAM10/DCIM/100HDDVR'
self.source_direcotry11= '/Volumes/CAM11/DCIM/100HDDVR'
self.path0="recording/CAM0"
self.path1="recording/CAM1"
self.path2="recording/CAM2"
self.path3="recording/CAM3"
self.path4="recording/CAM4"
self.path5="recording/CAM5"
self.path6="recording/CAM6"
self.path7="recording/CAM7"
self.path8="recording/CAM8"
self.path9="recording/CAM9"
self.path10="recording/CAM10"
self.path11="recording/CAM11"
self.cam0=os.path.join(self.Destination.get(), self.path0)
self.cam1=os.path.join(self.Destination.get(), self.path1)
self.cam2=os.path.join(self.Destination.get(), self.path2)
self.cam3=os.path.join(self.Destination.get(), self.path3)
self.cam4=os.path.join(self.Destination.get(), self.path4)
self.cam5=os.path.join(self.Destination.get(), self.path5)
self.cam6=os.path.join(self.Destination.get(), self.path6)
self.cam7=os.path.join(self.Destination.get(), self.path7)
self.cam8=os.path.join(self.Destination.get(), self.path8)
self.cam9=os.path.join(self.Destination.get(), self.path9)
self.cam10=os.path.join(self.Destination.get(), self.path10)
self.cam11=os.path.join(self.Destination.get(), self.path11)
self.p.start()
shutil.copytree(self.source_direcotry0, self.cam0)
shutil.copytree(self.source_direcotry1, self.cam1)
shutil.copytree(self.source_direcotry2, self.cam2)
# shutil.copytree(self.source_direcotry3, self.cam3)
# shutil.copytree(self.source_direcotry4, self.cam4)
# shutil.copytree(self.source_direcotry5, self.cam5)
# shutil.copytree(self.source_direcotry6, self.cam6)
# shutil.copytree(self.source_direcotry7, self.cam7)
# shutil.copytree(self.source_direcotry8, self.cam8)
# shutil.copytree(self.source_direcotry9, self.cam9)
# shutil.copytree(self.source_direcotry10, self.cam10)
# shutil.copytree(self.source_direcotry11, self.cam11)
self.p.stop()
self.status['text'] = "Files have been copyied".format(self.status)
def deletee(self):
send2trash('/Volumes/CAM0/DCIM')
send2trash('/Volumes/CAM1/DCIM')
send2trash('/Volumes/CAM2/DCIM')
# send2trash('/Volumes/CAM3/DCIM')
# send2trash('/Volumes/CAM4/DCIM')
# send2trash('/Volumes/CAM5/DCIM')
# send2trash('/Volumes/CAM6/DCIM')
# send2trash('/Volumes/CAM7/DCIM')
# send2trash('/Volumes/CAM8/DCIM')
# send2trash('/Volumes/CAM9/DCIM')
# send2trash('/Volumes/CAM10/DCIM')
# send2trash('/Volumes/CAM11/DCIM')
self.status['text'] = "Files have been moved to trash".format(self.status)
def client_exit(self):
exit()
def about_popup(self):
messagebox.showinfo("About", "This is software used to copy or delete files in bulk from the Absolute Zero VR camera")
#Creation of init_window
def init_window(self):
self.Source=StringVar()
self.Destination=StringVar()
# changing the title of our master widget
self.master.title("AZ Data Extractor")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
#Creating the menu
self.menubar = Menu(self.master)
#Creating submenues
self.filemenu = Menu(self.menubar, tearoff=0)
self.filemenu.add_command(label="Exit", command=root.quit)
self.menubar.add_cascade(label="File", menu=self.filemenu)
self.helpmenu = Menu(self.menubar, tearoff=0)
self.helpmenu.add_command(label="About", command=self.about_popup)
self.menubar.add_cascade(label="Help", menu=self.helpmenu)
#Displaying the menu
root.config(menu=self.menubar)
#Creating the intro label
l_instruction = Label(self, justify=CENTER, compound=TOP, text="Choose the destination for the copied files \n and press 'Go!' to start copyting", bg="#E6E6E6")
l_instruction.grid(columnspan=2, ipady=10)
l_instruction = Label(self, justify=CENTER, compound=TOP, text="Press 'Delete' to move all files \n from the camera to the trash", bg="#E6E6E6")
l_instruction.grid(row=6, columnspan=2, ipady=10)
# ttk.Style().configure('green/black.TButton', foreground='green', background='black')
#Creating the button
MyDestination=Entry(self, textvariable=self.Destination, bg="#E6E6E6")
MyDestination.grid(row=2, columnspan=2, ipady=10)
uploadButton = Button(self, text="Choose destination folder",command=lambda:self.Destination.set(fdialog.askdirectory()))
uploadButton.grid(row=3, columnspan=2, ipady=10)
goButton = Button(self, text="Go!",command=self.copyy)
goButton.grid(row=4, columnspan=2, ipady=10)
delButton = Button(self, text="Delete",command=self.deletee)
delButton.grid(row=7, columnspan=2, ipady=10)
self.p = ttk.Progressbar(self, orient=HORIZONTAL, length=300, mode='indeterminate')
self.p.grid(row=5)
self.img = ImageTk.PhotoImage(Image.open("az.png"))
self.panel = Label(self, image=self.img, bg="#E6E6E6")
self.display = self.img
self.panel.grid(row=8)
#resizing configuration
self.grid_columnconfigure(0,weight=1)
self.grid_columnconfigure(1,weight=1)
self.grid_rowconfigure(0,weight=1)
self.grid_rowconfigure(1,weight=1)
self.grid_rowconfigure(2,weight=1)
self.grid_rowconfigure(3,weight=1)
self.grid_rowconfigure(4,weight=1)
self.grid_rowconfigure(5,weight=1)
self.grid_rowconfigure(6,weight=1)
self.grid_rowconfigure(7,weight=1)
self.grid_rowconfigure(8,weight=1)
self.grid_rowconfigure(9,weight=1)
self.grid_rowconfigure(10,weight=1)
#status Bar
self.status = Label(self.master, text="Waiting for process to start...", bd=1, relief=SUNKEN, anchor=W)
self.status.pack(side=BOTTOM, fill=X)
# root window created. Here, that would be the only window, but you can later have windows within windows.
root = Tk()
root.resizable(width=False,height=False);
# root.configure(background='black');
# fm = Frame(root, width=300, height=200, bg="blue")
# fm.pack(side=TOP, expand=NO, fill=NONE)
#root.geometry("230x340")
#creation of an instance
app = Window(root)
#mainloop
root.mainloop()
Edit: Just as and additional problem that came up in the mean time I can't seem to change background colour of the buttons and the frames around entry field. I read up it could be because using MacOS platform, could that be? Any workarounds?