Python backup programm
Verfasst: Sonntag 18. Februar 2024, 11:47
Hallo zusammen,
ich bin neu hier im Forum und auch anfänger als Python programmierer, darum brauche ich eure Hilfe.
Habe vor einigen Tagen angefangen, ein Backup Programm in Python zu schreiben, jedoch stosse ich immer wieder auf einige schwierigkeiten.
Ich will, wenn ich den Haken gesetzt habe, dass das Programm wen ich auf Copy gedruckt habe, das Programm nur die angeklickte Dateien kopiert.
Dies ist ein Programm mit GUI:
Hat jemand eini Idee wie ich das lösen kann bzw. habe ich hier was falsch gemacht und was?
Besten Dank und Gruss
pyCoder
ich bin neu hier im Forum und auch anfänger als Python programmierer, darum brauche ich eure Hilfe.
Habe vor einigen Tagen angefangen, ein Backup Programm in Python zu schreiben, jedoch stosse ich immer wieder auf einige schwierigkeiten.
Ich will, wenn ich den Haken gesetzt habe, dass das Programm wen ich auf Copy gedruckt habe, das Programm nur die angeklickte Dateien kopiert.
Dies ist ein Programm mit GUI:
Code: Alles auswählen
#### IMPORT BIBLIOTHEK
from tkinter import *
from os import *
from tkinter import messagebox
import os
import shutil
import tkinter as tk
#### VARIABLES
bgColor = "#333333"
fgColor = "#fefefe"
titleFont = "Tahoma, 12"
stdFont = "Tahoma, 10"
chkBoxPadX = 40
chkBoxPadY = 2
getUsername = os.path.expanduser('~')
#### DEFINITIONS
def msgBox():
msg = Label(mainForm, text="nothing selected").pack(padx=200, pady=200)
def copy_all():
source_file = os.path.expanduser('~') + r"\\tmp\\copy_2\\"
destination_file = os.path.expanduser('~') + r"\\tmp\\test\\"
shutil.copytree(source_file, destination_file, symlinks=False, ignore=None, copy_function=shutil.copy2, ignore_dangling_symlinks=False, dirs_exist_ok=True)
#### MAIN FORM
mainForm = tk.Tk()
mainForm.geometry("800x600")
mainForm.title("Codat - Save files and copy back") :geek:
mainForm['bg'] = bgColor
#mainForm.iconbitmap('icon.ico')
mainForm.resizable(False, False)
chkBox_1 = IntVar()
chkBox_2 = IntVar()
class CheckBoxes:
chkBoxShow = 1
def __init__(chkBox, chkBoxLabel):
var = StringVar()
lblCheckbox = Label(mainForm, text="Standard selected files", width=30, anchor=NW, bg=bgColor, fg=fgColor, highlightbackground=bgColor, highlightthickness=0, font=titleFont)
lblCheckbox.grid(row=0, column=0, padx=20, pady=(20, 20), sticky=NW)
chkBox = Checkbutton(mainForm, text=chkBoxLabel, variable=chkBox_1, onvalue=chkBoxLabel, offvalue="", command=copy_all)
chkBox.config(bg=bgColor)
chkBox.config(fg=fgColor)
chkBox.config(highlightbackground=bgColor)
chkBox.config(highlightthickness=0)
chkBox.config(activebackground=bgColor)
chkBox.config(activeforeground=fgColor)
chkBox.grid(row=CheckBoxes.chkBoxShow, column=0, sticky=W, padx=50, pady=5)
CheckBoxes.chkBoxShow+=1
CheckBoxes("Desktop")
CheckBoxes("Documents")
CheckBoxes("Favorite")
#### BUTTONS
btnCopy = tk.Button(mainForm, text="Copy", width=10, command=copy_all)
btnCopy.place(x=5, y=500)
btnExit = tk.Button(mainForm, text="Exit", width=15, command=mainForm.quit)
btnExit.place(x=675, y=550)
#### SCREEN POSITION
scrWidth = 800
scrHeight = 600
screenW = mainForm.winfo_screenwidth()
screenH = mainForm.winfo_screenheight()
screenX = (screenW/2) - (scrWidth/2)
screenY = (screenH/2) - (scrHeight/2)
#### MAIN FORM VIEW
mainForm.geometry('%dx%d+%d+%d' % (scrWidth, scrHeight, screenX, screenY))
mainForm.mainloop()
Hat jemand eini Idee wie ich das lösen kann bzw. habe ich hier was falsch gemacht und was?
Besten Dank und Gruss
pyCoder