I am making a tkinter
window where it checks if the correct string was passed, but if I put the wrong string, then I get this error:
AttributeError: 'str' object has no attribute 'items'
Here is my code:
from tkinter import *
root = Tk()
e = Entry(root)
e.grid(row=0, column=0)
def buttonclick():
if e.get() == "12345":
goodLabel = Label(root, text="Good!")
goodLabel.grid(row=3, column=0)
else:
badLabel = Label(root, "Bad!")
badLabel.grid(row=3, column=0)
button = Button(root, text="Submit", command=buttonclick)
button.grid(row=2, column=0)
CodePudding user response:
try this
from tkinter import *
root = Tk()
e = Entry(root)
e.grid(row=0, column=0)
def buttonclick():
if e.get() == "12345":
goodLabel = Label(root, text="Good!")
goodLabel.grid(row=3, column=0)
else:
badLabel = Label(root, text="Bad!")
badLabel.grid(row=3, column=0)
button = Button(root, text="Submit", command=buttonclick)
button.grid(row=2, column=0)
root.mainloop()
Just use text="Bad!"
is this what you're looking for??