Home > Blockchain >  AttributeError: 'Entry' object has no attribute 'split'
AttributeError: 'Entry' object has no attribute 'split'

Time:01-17

from tkinter import *
from tkinter import ttk

root = Tk()
root.geometry("600x400")
root.resizable(False, False)


def nameLength(event):
    str(input)
    length = input.split()
    length1 = len(garums)

    myLabel = Label(root, text=length1.get()).pack( )

choice = ("Word count", "Delete symbol", "Change 1st word with last word")

options = StringVar()
options.set("Choose an option")

input = Entry(root)
input.pack()



menu = OptionMenu(root, options, *choice, command=nameLength)
menu.pack(pady=20)


root.mainloop()

When I run my code, I tend to get an error saying that AttributeError: 'Entry' object has no attribute 'split'

I've tried googling it and noone seems to have the same exact problem as I do. Would appreciate if someone would help or explain!

CodePudding user response:

input is an instance of an Entry object. Like the error says, it has no method split. Since it is an Entry object, it is not a string object. You must use methods to get strings into and out of Entry objects.

input_value = input.get()
length = input_value.split()
  •  Tags:  
  • Related