I am fetching a cell from an excelsheet to display as a label in my TKinter window. When there is no match it should delete the text. I find the name and the results are as I want it to
When I remove the text from my name entry I want the name to dissapear. But then this happens.
Looks like it's trying to overwrite the text with blank text.
My code :
from tkinter import *
import csv
import time
from openpyxl import load_workbook
class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.output()
def clock(self):
self.hour = time.strftime("%H")
self.minute = time.strftime("%M")
self.second = time.strftime("%S")
self.klockan.config(text = self.hour + ":" + self.minute + ":" + self.second)
self.klockan.after(1000, self.clock)
#Leta värden i excel namn.xlsx
def excelinfo(self):
self.wb = load_workbook("namn.xlsx",read_only=True)
self.ws = self.wb.active
self.excelnamn = self.excelnamn = Label(text="",font=('Arial', 10)).grid(row=1,column=2)
if len(self.namn.get()) > 2:
for i in self.ws.rows:
if i[0].value == self.namn.get():
self.excelnamn = Label(text=i[1].value,font=('Arial', 10)).grid(row=1,column=2)
# self.excelnamn = self.excelnamn(text=i[1])
# self.excelföretag = i[2].value
else:
pass
self.namn.after(1000, self.excelinfo)
def output(self):
#Tid
self.klockan = Label(root, text='', font=('Arial',25))
self.klockan.grid(row=0, column=2)
self.clock()
#Etiketter
Label(text='Namn:').grid(row=1,column=0)
self.namn = Entry(root, width=10)
self.namn.grid(row=1,column=1)
self.namn.insert(END,"ES")
self.excelinfo()
def writeToFile(self):
self.checknum()
with open('Test.csv', 'a') as f:
w=csv.writer(f, quoting=csv.QUOTE_ALL)
w.writerow([
self.namn.get()
])
self.clear()
if __name__ == "__main__":
root=Tk()
root.title('Auto Logger')
root.geometry('800x600')
app=App(master=root)
app.mainloop()
root.mainloop()
i've tried altering the code using .destroy() and .grid_forget() but destoy gives me no attribute to destroy error. and grid.forget() the name no longer appears in the box.
#Leta värden i excel namn.xlsx
def excelinfo(self):
self.wb = load_workbook("namn.xlsx",read_only=True)
self.ws = self.wb.active
self.excelnamn = self.excelnamn = Label(text="",font=('Arial', 10))
self.excelnamn.grid(row=1,column=2)
if len(self.namn.get()) > 2:
for i in self.ws.rows:
if i[0].value == self.namn.get():
self.excelnamn = Label(text=i[1].value,font=('Arial', 10))
self.excelnamn.grid(row=1,column=2)
# self.excelnamn = self.excelnamn(text=i[1])
# self.excelföretag = i[2].value
else:
self.excelnamn.grid_forget()
self.namn.after(1000, self.excelinfo)
self.excelnamn.destroy()
AttributeError: 'NoneType' object has no attribute 'destroy'