How do I fix this: TypeError: Entry.get() takes 1 positional argument but 3 were given

Question:

I am very new to coding and can’t figure out what is wrong. I am just trying to print something that the user types in a text box. I have a button that calls a function to take the info from the textbox, do some math with the number, then print its output in the console.

When I run the program it starts off fine but when I enter a digit into the first box and press the button this error appears.

File "/Users/Owner/PycharmProjects/gui thing/venv/new gui.py", line 29, in <lambda>
    printbutton = Button(bottomframe, text="Run Algorithm", command=lambda: get_input())
  File "/Users/Owner/PycharmProjects/gui thing/venv/new gui.py", line 6, in get_input
    year = boxYear.get("1.0", "end-1c")
TypeError: Entry.get() takes 1 positional argument but 3 were given
from tkinter import *
root = Tk()

root.geometry("500x500")
def get_input():
    year = boxYear.get("1.0", "end-1c")
    p1 = (int(year) // 12)
    p2 = (int(year) % 12)
    p3 = (p2 // 4)
    p4 = (p1 + p2 + p3)
    days = ['wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'monday', 'tuesday']
    p5 = (p4 // 7)
    if p4 >= 7 and p4 <= 14:
        p6 = (int(p4 - 7))
    elif p4 >= 7 and p4 > 14:
        p6 = (int(p4 - 14))
    else:
        p6 = (int(p4))
    if p6 == 7:
        p6 = 0
    print(days[int(p6)])
topframe = Frame(root)
topframe.pack()
bottomframe = Frame(root)
bottomframe.pack(side=BOTTOM)

quitbutton = Button(bottomframe, text= "Quit Program", command=bottomframe.quit)
quitbutton.grid()
printbutton = Button(bottomframe, text="Run Algorithm", command=lambda: get_input())
printbutton.grid()

boxYear = Entry(topframe)
boxMonth = Entry(topframe)
boxDay = Entry(topframe)

boxYear.grid(row=0, column=1, padx=10, pady=10)
boxMonth.grid(row=1, column=1, padx=10, pady=10)
boxDay.grid(row=2, column=1, padx=10, pady=10)

l1 = Label(topframe, text="Year: ")
l2 = Label(topframe, text="Month: ")
l3 = Label(topframe, text="Day: ")

l1.grid(row=0, column=0)
l2.grid(row=1, column=0)
l3.grid(row=2, column=0)

I have tried moving things around and Turing on and off certain part to see what’s causing the issue. I’ve looked at it for a while and can’t see anything wrong but as I said I have no idea what I am doing as I just started coding two weeks ago.

Asked By: MAKatcher

||

Answers:

The get method takes no parameters (other than self, which is why the error mentions one parameter). You are calling it as if the widget was a Text widget, but it’s an Entry widget. The way to call get on an entry widget is by passing no parameters:

year = boxYear.get()
Answered By: Bryan Oakley