Apologies if it is repetitive but I am struggling to find a solution with this. I am trying to write a decorator function below.
def search_func(sheetname):
def insider(function):
def wraper(*args, **kwargs):
file = openpyxl.load_workbook("C:\\Users\khisr\OneDrive\Documents\TestPage.xlsx")
currnet_sheet = file[sheetname]
function(currnet_sheet)
return wraper
return insider
@search_func('Passwords')
def Longin(self, currnet_sheet):
Name = self.User_name.get() + str(self.Password.get())
for i in range(1,current_sheet.max_row +1):
for j in range(1,current_sheet.max_column+1):
if current_sheet.cell(i,j).value == Name:
The function is called with a button;
self.Button = tk.Button(self.Main_frame, text='Enter', bg = 'green', command = self.Longin)
I get an error
"Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/khisr/OneDrive/Documents/PythonProjects/Dubai_Project/login.py", line 71, in wraper
function(currnet_sheet)
TypeError: Longin() missing 1 required positional argument: 'currnet_sheet"
Any help or commend is much appreciated.
Cheers
Longinmethod. Probably becausetk.Buttonexpects what you pass to be function not a method (methods requireself). If you wantLonginto be part of a class then try turning it into a@staticmethod.return function(currnet_sheet), otherwise if you decorate a method/function that returns something the decorator will consume it.self. Try using a lambda:self.Button = tk.Button(self.Main_frame, text='Enter', bg='green', command=lambda sheet: self.Longin(sheet))