I'm not sure why but when I try to print a list after adding data to it via user input and append, it comes up with a weird error
Question:
I’m fairly new to coding but when I tried to make a list and put data inside of it using append and an entry so I could have user input data it came back with a really weird error.
<bound method Entry.get of <tkinter.Entry object .!entry>>
I don’t even think that this is an error, rather just a way that the list is being printed and I’m not sure why. If anyone could please help that would be really appreciated, thank you!
This is the code it’s not super advanced and there’s probably a lot of redundancy that could be reduced but I’m fairly new to python so I just wanted to try it out.
`
import tkinter
from tkinter import messagebox
TemperatureInfo = []
weather = tkinter.Tk()
weather.geometry("200x300")
weather.update()
messagebox.showinfo("Weather App Explanation", "Hello! Welcome to my app that collects weather data! Input different aspects about the weather for the weekdays here and I will send back information on the data you entered!")
expln = tkinter.Label(weather, text = "Put the temperatures in here for Monday - Wednesday!").pack()
weather1 = tkinter.Entry(weather)
weather1.pack(pady = 10)
weather2 = tkinter.Entry(weather)
weather2.pack(pady = 10)
weather3 = tkinter.Entry(weather)
weather3.pack(pady = 10)
weather4 = tkinter.Entry(weather)
weather4.pack(pady = 10)
weather5 = tkinter.Entry(weather)
weather5.pack(pady = 10)
def addTempData():
TemperatureInfo.append(weather1.get)
TemperatureInfo.append(weather2.get)
TemperatureInfo.append(weather3.get)
TemperatureInfo.append(weather4.get)
TemperatureInfo.append(weather5.get)
def printInfo():
print(TemperatureInfo)
done = tkinter.Button(weather, text = "Done", command = addTempData).pack()
printing = tkinter.Button(weather, text = 'print', command = printInfo).pack()
weather.mainloop()
`
I tried to see if it was an issue with the list not being a string or something similar and that didn’t change anything, it just gave me more errors.
Answers:
The error you are seeing is because you are not calling the get() method of the Entry widget, but rather you are appending the method itself to the TemperatureInfo list by doing
TemperatureInfo.append(weather1.get)
To fix this error, you need to call the get() method on each of the Entry widgets in the addTempData function.
Your addTempData function should look like this :
def addTempData():
TemperatureInfo.append(weather1.get())
TemperatureInfo.append(weather2.get())
TemperatureInfo.append(weather3.get())
TemperatureInfo.append(weather4.get())
TemperatureInfo.append(weather5.get())
I’m fairly new to coding but when I tried to make a list and put data inside of it using append and an entry so I could have user input data it came back with a really weird error.
<bound method Entry.get of <tkinter.Entry object .!entry>>
I don’t even think that this is an error, rather just a way that the list is being printed and I’m not sure why. If anyone could please help that would be really appreciated, thank you!
This is the code it’s not super advanced and there’s probably a lot of redundancy that could be reduced but I’m fairly new to python so I just wanted to try it out.
`
import tkinter
from tkinter import messagebox
TemperatureInfo = []
weather = tkinter.Tk()
weather.geometry("200x300")
weather.update()
messagebox.showinfo("Weather App Explanation", "Hello! Welcome to my app that collects weather data! Input different aspects about the weather for the weekdays here and I will send back information on the data you entered!")
expln = tkinter.Label(weather, text = "Put the temperatures in here for Monday - Wednesday!").pack()
weather1 = tkinter.Entry(weather)
weather1.pack(pady = 10)
weather2 = tkinter.Entry(weather)
weather2.pack(pady = 10)
weather3 = tkinter.Entry(weather)
weather3.pack(pady = 10)
weather4 = tkinter.Entry(weather)
weather4.pack(pady = 10)
weather5 = tkinter.Entry(weather)
weather5.pack(pady = 10)
def addTempData():
TemperatureInfo.append(weather1.get)
TemperatureInfo.append(weather2.get)
TemperatureInfo.append(weather3.get)
TemperatureInfo.append(weather4.get)
TemperatureInfo.append(weather5.get)
def printInfo():
print(TemperatureInfo)
done = tkinter.Button(weather, text = "Done", command = addTempData).pack()
printing = tkinter.Button(weather, text = 'print', command = printInfo).pack()
weather.mainloop()
`
I tried to see if it was an issue with the list not being a string or something similar and that didn’t change anything, it just gave me more errors.
The error you are seeing is because you are not calling the get() method of the Entry widget, but rather you are appending the method itself to the TemperatureInfo list by doing
TemperatureInfo.append(weather1.get)
To fix this error, you need to call the get() method on each of the Entry widgets in the addTempData function.
Your addTempData function should look like this :
def addTempData():
TemperatureInfo.append(weather1.get())
TemperatureInfo.append(weather2.get())
TemperatureInfo.append(weather3.get())
TemperatureInfo.append(weather4.get())
TemperatureInfo.append(weather5.get())