NameError: name 'search_entry' is not defined
Verfasst: Freitag 4. November 2022, 07:17
ich hab e mit ein klienes Programm geschrieben welches in Datein sucht anhand bestimmeter Filterwerte. Als CMD läuft das Programm. Jetzt wollte ich es "aufhübschen" mit ner GUI und scheitere daran. Ich blicks grad nicht. Wo liegt mein Problem?
Ich habe ein Problem mit den Variablen:
ich bekomme immer den Fehler : NameError: name 'search_entry' is not defined
ich hab es auch schon so versucht, ging aber auch nicht.
Hier mal der komplette Code:
Ich habe ein Problem mit den Variablen:
Code: Alles auswählen
search_terms.append (search_entry.get())
terms = search_entry.get()
src = entry_source.get()
dst = entry_destination.get()
ext = entry_file.get()
start = entry_start.get()
end = entry_end.get()
ich hab es auch schon so versucht, ging aber auch nicht.
Code: Alles auswählen
search_terms.append (search_entry.get())
terms = (search_entry.get())
src = (entry_source.get())
dst = (entry_destination.get())
ext = (entry_file.get())
start = (entry_start.get())
end = (entry_end.get())
Hier mal der komplette Code:
Code: Alles auswählen
#!/usr/bin/python
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk
import tkinter as tk
import os
import shutil
import time
from datetime import datetime
search_terms = []
search_terms.append (search_entry.get())
terms = search_entry.get()
src = entry_source.get()
dst = entry_destination.get()
ext = entry_file.get()
start = entry_start.get()
end = entry_end.get()
def dateRange(createdDate, startDate, endDate):
createdDate = datetime.strptime(createdDate, '%a %b %d %H:%M:%S %Y')
startDate = datetime.strptime(startDate, '%d/%m/%Y/%H/%M')
endDate = datetime.strptime(endDate, '%d/%m/%Y/%H/%M')
return startDate < createdDate < endDate
for filename in os.listdir(src):
created = time.ctime(os.path.getmtime(src + filename))
if filename.endswith('.' + ext) and dateRange(created, start, end):
shutil.copy(src + filename, dst)
print("[+] File transferred " + filename + created)
for f in os.listdir(dst):
text = '\n'.join( open(os.path.join(dst,f)).readlines() )
if any([term in text for term in search_terms]):
print (f)
else:
os.remove((dst) + (f))
def output_delete():
data_text.delete(1.0, END)
def search_delete():
search_entry.delete(1.0, END)
def delete_all():
entry_start.delete(0, 'end')
entry_end.delete(0, 'end')
entry_file.delete(0, 'end')
entry_notice.delete(0, 'end')
root = Tk()
root.title("Search in Files - by HoLaHe - Version 1.0 - Stand November 2022")
root.geometry("680x480")
root.resizable(width=True, height=True)
root.withdraw()
root.deiconify()
input_label = Label(root, text=" ", font='Helvetica 10 bold')
input_label.grid(row=0, column=2, padx=5, sticky='w')
input_label = Label(root, text="Bitte Filterdaten eintragen: ", font='Helvetica 10 bold')
input_label.grid(row=1, column=2, padx=5, sticky='w')
label_start = Label(root, text="Start Datum und Uhrzeit: ", width=25)
label_start.grid(row=2, column=1, padx=5, sticky='e')
entry_start = Entry(root, width=55)
entry_start.insert(END, "Beispiel: 24/10/2022/08/00")
entry_start.grid(row=2, column=2, padx=5, sticky='e')
label_end = Label(root, text="End Datum und Uhrzeit:", width=25)
label_end.grid(row=3, column=1, sticky='e')
entry_end = Entry(root, width=55)
entry_end.insert(END, "Beispiel: 24/10/2022/08/00")
entry_end.grid(row=3, column=2, padx=5, sticky='e')
label_file = Label(root, text="Datei Type: ", width=25)
label_file.grid(row=4, column=1, sticky='e')
entry_file = Entry(root, width=55)
entry_file.insert(END, "txt")
entry_file.grid(row=4, column=2, padx=5, sticky='e')
label_source = Label(root, text="Quellverzeichniss: ", width=25)
label_source.grid(row=5, column=1, sticky='e')
entry_source = Entry(root, width=55)
entry_source.insert(END, "C:\demo\sbc\ out\ ")
entry_source.grid(row=5, column=2, padx=5, sticky='e')
label_destination = Label(root, text="Zielverzeichniss: ", width=25)
label_destination.grid(row=6, column=1, sticky='e')
entry_destination = Entry(root, width=55)
entry_destination.insert(END, "C:\demo\sbc\ ")
entry_destination.grid(row=6, column=2, padx=5, sticky='e')
label_leer_ = Label(root, text="", width=15)
label_leer_.grid(row=9, column=1, rowspan= 5)
save_button = Button(root, text="Eingaben zurücksetzen", command=delete_all, width=20)
save_button.grid(row=2, column=5)
label_leer = Label(root, text="", width=55)
label_leer.grid(row=5, column=1, columnspan= 2)
search_label = Label(root, text="Bitte Suchbegriff eingeben: ", font='Helvetica 10 bold', width=30)
search_label.grid(row=9, column=2, padx=5, sticky='w')
search_button = Button(root, text="Suchen", command=dateRange, width=20)
search_button.grid(row=10, column=5)
search_entry = Entry(root, width=55)
search_entry.insert(END, "Beispiel: 49301234 oder sipbusiness.provider.de")
search_entry.grid(row=10, column=2, padx=5)
search_button = Button(root, text="Ausgabe löschen", command=output_delete, width=20)
search_button.grid(row=15, column=5, sticky='n')
output_label = Label(root, text="Die gesuchten Daten sind: ", font='Helvetica 10 bold')
output_label.grid(row=14, column=2, padx=2, sticky='w')
label_leer1 = Label(root, text="", width=55)
label_leer1.grid(row=13, column=2, columnspan= 2)
data_text = Text(root, width=42, height=15)
data_text.grid(row=15, column=2, sticky='w')
# create a scrollbar widget and set its command to the text widget
scrollbar = ttk.Scrollbar(root, orient='vertical', command=data_text.yview)
scrollbar.grid(row=15, column=3, sticky=tk.NS)
data_text['yscrollcommand'] = scrollbar.set
root.mainloop()