Reputation: 13
I am trying to pass the hours variable from the GetHours function into the CSVtablemaker function but it gives me the error of:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "\\Marge\Users\14\CharKall14\My Documents\Year 13\Computing\Programming Project\[MAIN] FILE v3.py", line 81, in <lambda>
self.Hours1Entry = tk.Button(frameHours, text="1 Hour", command= lambda: self.GetHours(1))
TypeError: GetHours() missing 1 required positional argument: 'hours'
I looked at tons of pages trying to find an answer to this, and it's probably pretty simple but I just don't get it. Sorry for my poor coding, I'm still pretty new.
Here's the whole class as it may not make sense without it:
def __init__(self, master):
frame = tk.LabelFrame(master, text="Main Menu", padx=100, pady=10)
frame.grid(row=0, column=0, padx=15, pady=15)
# Create timetable button
createTimetable = tk.Button(frame, text="Create Timetable", command=self.CreateTimetable)
createTimetable.grid(row=0, column=0, padx=4, pady=4)
# Exit program button
exitProgram = tk.Button(frame, text="Exit Program", command=self.CloseWindow)
exitProgram.grid(row=1, column=0, padx=4, pady=4)
self.hours = None
def CloseWindow(self):
# Closes the window when the close button is pressed
root.destroy()
def GetSubjects(self):
# Retrieves the subjects from what the user enters in the tableWindow
self.subject1 = self.subject1entry.get()
self.subject2 = self.subject2entry.get()
self.subject3 = self.subject3entry.get()
print(self.subject1)
print(self.subject2)
print(self.subject3)
def GetHours(self, numhours, hours):
if numhours == 1:
self.hours = 1
elif numhours == 2:
self.hours = 2
elif numhours == 3:
self.hours = 3
else:
print("unexpected error")
def CreateTimetable(self):
tableWindow = tk.Toplevel(root)
tableWindow.title('Timetable Maker Window')
tableWindow.geometry("800x500+400+200")
tableFrame = tk.LabelFrame(tableWindow, text="Enter Subjects", padx=100, pady=10)
tableFrame.grid(row=0, column=0, padx=15, pady=15)
# Subject labels
subjectlabel1 = tk.Label(tableFrame, text="Enter your first subject:")
subjectlabel2 = tk.Label(tableFrame, text="Enter your second subject:")
subjectlabel3 = tk.Label(tableFrame, text="Enter your third subject:")
# Subject entry boxes
self.subject1entry = tk.Entry(tableFrame)
self.subject2entry = tk.Entry(tableFrame)
self.subject3entry = tk.Entry(tableFrame)
# Puts subject entry boxes on screen
self.subject1entry.grid(row=0, column=1, padx=4, pady=4)
self.subject2entry.grid(row=1, column=1, padx=4, pady=4)
self.subject3entry.grid(row=2, column=1, padx=4, pady=4)
# Puts subject labels on screen
subjectlabel1.grid(row=0, column=0, padx=4, pady=4)
subjectlabel2.grid(row=1, column=0, padx=4, pady=4)
subjectlabel3.grid(row=2, column=0, padx=4, pady=4)
# Creates subject confirm button
subjectConfirm = tk.Button(tableFrame,text="Press to confirm subjects", command=self.GetSubjects)
# Puts subject confirm button on screen
subjectConfirm.grid(row=3, column=0, padx=4, pady=4)
frameHours = tk.LabelFrame(tableWindow, text="Hours tab", padx=100, pady=10)
frameHours.grid(row=1, column=0, padx=15, pady=15)
self.Hours1Entry = tk.Button(frameHours, text="1 Hour", command= lambda: self.GetHours(1))
self.Hours1Entry.grid(row=0, column=0, padx=4, pady=4)
self.Hours2Entry = tk.Button(frameHours, text="2 Hours", command= lambda: self.GetHours(2))
self.Hours2Entry.grid(row=1, column=0, padx=4, pady=4)
self.Hours3Entry = tk.Button(frameHours, text="3 Hours", command= lambda: self.GetHours(3))
self.Hours3Entry.grid(row=2, column=0, padx=4, pady=4)
def CSVtablemaker(self, hours):
hour_val = self.hours
while hour_val == 1:
print("woo hoo it works")```
Upvotes: 0
Views: 39
Reputation: 378
Your GetHours method requires 3 arguments, but the lambda function gives only one.
def GetHours(self, numhours, hours)
...
command= lambda: self.GetHours(1)
The input "1" goes as the parameter "numhours". The other required parameter "hours" is not given.
--
Looking at your GetHours function, it looks like the extra input parameter "hours" is not used. You should be able to fix your issue by removing it as an input parameter when defining the method.
Upvotes: 2