Hi,
I've got something that just cropped up. This is not a tkinter question, though I'm using tkinter in the app. I've got some functions that are called from some tkinter objects, so I had to define them with 'self' as an input parameter, as the code was requiring that.
Except, when I'm trying to call the function from within another function, it gives me an error if I include 'self', and gives me an error if I exclude 'self'.
Here is the function definition. I should also stipulate that this is not defined within a class:
I've got something that just cropped up. This is not a tkinter question, though I'm using tkinter in the app. I've got some functions that are called from some tkinter objects, so I had to define them with 'self' as an input parameter, as the code was requiring that.
Except, when I'm trying to call the function from within another function, it gives me an error if I include 'self', and gives me an error if I exclude 'self'.
Here is the function definition. I should also stipulate that this is not defined within a class:
def updateMainTasks(self):
global mydict
cnxn= sqlite3.connect(sqlFileLoc)
mydict, data = getCboMainTaskList()
#try is to catch that mydict-key.get value exception when it is null
try:
#compensating for when Headline is not filled in yet.
if HeadlineMainTask.get()== '':
thisTask =cboMainTask.get()
elif HeadlineMainTask.get() != cboMainTask.get():
thisTask=HeadlineMainTask.get()
else: thisTask = cboMainTask.get()
if cboMainTask.get().__len__() !=0:
sql='Select TaskID, Headline, Requester, Headline, Explanation,RequestDate, \
Complete, Acknowledged,DueDate from MainTasks \
where TaskID = ' + str(mydict[thisTask])
df=pd.read_sql_query(sql, cnxn)
#clear then fill cboTask
cboMainTask['values']=list(mydict)
#thiscur.close()
#Requester
RequesterMainTask.delete(0,'end')
try:
RequesterMainTask.insert(0,df.iat[0,2])
except:
pass
#Headline
HeadlineMainTask.delete(0,'end')
HeadlineMainTask.insert(0,df.iat[0,3])
#Explanation
ExplanationMainTask.delete('1.0','end')
ExplanationMainTask.insert('1.0',df.iat[0,4])
#Request Date
RequestDateMainTask.delete(0,'end')
try:
RequestDateMainTask.insert(0,df.iat[0,5])
except:
pass
#Due Date
DueDateMainTask.delete(0,'end')
try:
DueDateMainTask.insert(0,df.iat[0,8])
except:
pass
#Complete
if df.iat[0,6]=='1':
ChkButtonCompleteMainTask.select()
else:
ChkButtonCompleteMainTask.deselect()
#Acknowledged
if df.iat[0,7]== '1':
ChkButtonAcknowledgedMainTask.select()
else:
ChkButtonAcknowledgedMainTask.deselect()
#filter down cboTaskSteps
cboTaskStep.set('')
sql2="Select StepDescription, TaskStepID \
from TaskSteps where TaskID = " + str(mydict[thisTask])
thiscur=cnxn.cursor()
thiscur.execute(sql2)
cnxn.commit()
mydict=dict(thiscur.fetchall())
data = list(mydict.keys())
cboTaskStep['values']=list(mydict)
if mydict.__len__() > 0:
cboTaskStep.current(0)
#update taskStepList
taskStepList.delete(0,'end')
for c in list(mydict):
taskStepList.insert('end',c)
#filter down cboSubTasks
#print(str(mydict[cboTaskStep.get()]))
cboSubTasks.set('')
#If no record, don't do it.
if mydict.__len__()> 0:
sql2="Select StepDescription, SubTaskStepID \
from SubTasks where TaskStepID = " + str(mydict[cboTaskStep.get()])
thiscur=cnxn.cursor()
thiscur.execute(sql2)
cnxn.commit()
mydict=dict(thiscur.fetchall())
data = list(mydict.keys())
cboSubTasks['values']=list(mydict)
if mydict.__len__() > 0:
cboSubTasks.current(0)
#clears the screen when you hit the clear button
else:
sql='Select TaskID, Headline, Requester, Headline, Explanation,RequestDate, \
Complete, Acknowledged,DueDate from MainTasks \
where TaskID is null'
RequesterMainTask.delete(0,'end')
HeadlineMainTask.delete(0,'end')
ExplanationMainTask.delete('1.0','end')
RequestDateMainTask.delete(0,'end')
DueDateMainTask.delete(0,'end')
ChkButtonCompleteMainTask.deselect()
ChkButtonAcknowledgedMainTask.deselect()
cnxn.close()
#unset dirty flag on Save button
btnsaveMainTasks.config(bg="silver")
#update history of selections at top of screen
displayHistory()
except:
pass
returnHere is the code from where it is being called, down towards the bottom. I can't include the whole program as it is too extensive.def saveMainTasks():
#saves dirty fields to database
global ChkComplete1
global ChkAcknowledged1
global mydict
mydict, data = getCboTaskList()
#Try to save an existing record with a TaskID
if cboTask.get() != '':
sql="Update MainTasks set \
Requester = '" + RequesterMainTask.get() + "', \
Headline = '" + HeadlineMainTask.get() + "', \
Explanation= '" + ExplanationMainTask.get('1.0','end') + "', \
RequestDate= '" + RequestDateMainTask.get() + "', \
DueDate= '" + DueDateMainTask.get() + "', \
Complete = '" + str(ChkComplete1.get()) + "', \
Acknowledged= '" + str(ChkAcknowledged1.get()) +"' \
Where TaskID = " + str(mydict[cboTask.get()])
#If that fails, try to add a new record
else:
sql="Insert into MainTasks (Requester, Headline, Explanation, RequestDate, DueDate, Complete, Acknowledged) \
Values('" +RequesterMainTask.get()+ "', '" + HeadlineMainTask.get()+ "', '" + ExplanationMainTask.get('1.0','end') + "', '"+ RequestDateMainTask.get() + "', ' \
" + DueDateMainTask.get()+ "', '" + str(ChkComplete1.get()) + "','" + str(ChkAcknowledged1.get()) + "')"
cnxn= sqlite3.connect(sqlFileLoc)
c=cnxn.cursor()
c.execute(sql)
cnxn.commit()
#refresh combo box after delete
c.execute('Select Headline, TaskID from MainTasks')
cnxn.commit()
mydict=dict(c.fetchall())
data = list(mydict.keys())
updateMainTasks()
#don't add key reference again. only one works.
cboTask.config(values=data)
c.close()
cnxn.close()
btnsaveMainTasks.config(bg="silver")This is also where that updateMainTasks function is being called, from a widget. This is where I think it is requiring me to use 'self', even though it does not call it with a parameter at this point.btnRefreshMainTask = tk.Button(maintaskframe, command=updateMainTasks, text = "Refresh", bg="silver") btnRefreshMainTask.place(x=col2+240, y=y7, width=60)The error I get if I don't call it with the 'self' parameter is:
Output:updateMainTasks() missing 1 required positional argument: 'self'The error I get when I do call with 'self' is:Output:name 'self' is not definedThing is, the was working previously, and I don't know what change caused it to break. Any ideas appreciated. I'm finding the constraints imposed by tkinter a little exasperating.
