我正在制作一個tkinter視窗,它檢查是否傳遞了正確的字串,但是如果我輸入了錯誤的字串,則會出現此錯誤:
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)
uj5u.com熱心網友回復:
嘗試這個
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!"
這是你要找的?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/344140.html
上一篇:面試官:JavaScript如何實作陣列拍平(扁平化)方法?
下一篇:在tkinter樹視圖中合并節點
