Tkinter error: AttributeError: 'str' object has no attribute 'items'
Tkinter error: AttributeError: 'str' object has no attribute 'items'
我正在制作一个 tkinter
window,它会检查是否传递了正确的字符串,但如果我输入了错误的字符串,则会出现此错误:
AttributeError: 'str' object has no attribute 'items'
这是我的代码:
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)
试试这个
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()
只需使用text="Bad!"
这是您要找的东西吗??
我正在制作一个 tkinter
window,它会检查是否传递了正确的字符串,但如果我输入了错误的字符串,则会出现此错误:
AttributeError: 'str' object has no attribute 'items'
这是我的代码:
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)
试试这个
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()
只需使用text="Bad!"
这是您要找的东西吗??