Home > Software engineering >  TypeError: Entry.get() got an unexpected keyword argument 'textvariable'
TypeError: Entry.get() got an unexpected keyword argument 'textvariable'

Time:04-01

I was trying to run the following code using Tkinter libary -

long = tk.Label(menu_add, text='Longitude', font=letter_font)
long_input = Entry.get(menu_add, textvariable=long, font=letter_font)

I got this error -

File "C:\Users\User\PycharmProjects\pythonProject\seismology.py", line 48, in add
 long_input = Entry.get(menu_add, textvariable=long, font=letter_font)
TypeError: Entry.get() got an unexpected keyword argument 'textvariable'

Using tk.Entry instead of Entry.get fixes the problem, but my objective is to save the user entry to a file later. Below code uses Tk.Entry -

long = tk.Entry(menu_add, text='Longitude', font=letter_font)
long_input = tk.Entry(menu_add, textvariable=long, font=letter_font)

Then I got this error -

File "C:\Users\User\PycharmProjects\pythonProject\seismology.py", line 26, in save
    open('seismology.csv', 'a').write('\n'.join(lst_data)   '\n')
TypeError: sequence item 0: expected str instance, Entry found

Code to save in the file -

def save():
    open('seismology.csv', 'a').write('\n'.join(lst_data)   '\n')

The values of the Entries are saved to an list, named lst_data to later be saved to the file -

long.grid(row=3, column=0)
long_input.grid(row=3, column=1)

d = long_input

global lst_data
lst_data = [a,b,c,d,e,f]

full code-

https://imgur.com/a/rCcdu7T

Any help is appreciated! ^^

CodePudding user response:

You can't use the Entry.get() method in Python as Entry is a Tkinter module, so you have to insert it as tk.Entry() only.

As for the second error, you are getting this error because you are trying to use a list type in a .join() code. .join() only accepts a string so try replacing open('seismology.csv', 'a').write('\n'.join(lst_data) '\n') with open('seismology.csv', 'a').write('\n'.join(str(lst_data)) '\n')

Then your error will be fixed.

  • Related