Tôi đã thấy một vài bài đăng khác có thông báo lỗi tương tự nhưng không thể tìm thấy giải pháp khắc phục sự cố trong trường hợp của tôi.Tkinter: AttributeError: đối tượng NoneType không có thuộc tính nào nhận được
Tôi đã thử một chút với TkInter và tạo một giao diện người dùng rất đơn giản. Mã sau-
from string import *
from Tkinter import *
import tkMessageBox
root=Tk()
vid = IntVar()
def grabText(event):
if entryBox.get().strip()=="":
tkMessageBox.showerror("Error", "Please enter text")
else:
print entryBox.get().strip()
root.title("My Sample")
root.maxsize(width=550, height=200)
root.minsize(width=550, height=200)
root.resizable(width=NO, height=NO)
label=Label(root, text = "Enter text:").grid(row=2,column=0,sticky=W)
entryBox=Entry(root,width=60).grid(row=2, column=1,sticky=W)
grabBtn=Button(root, text="Grab")
grabBtn.grid(row=8, column=1)
grabBtn.bind('<Button-1>', grabText)
root.mainloop()
Tôi có giao diện người dùng và chạy. Khi tôi bấm vào nút Grab
, tôi nhận được lỗi sau trên console:
C:\Python25>python.exe myFiles\testBed.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
return self.func(*args)
File "myFiles\testBed.py", line 10, in grabText
if entryBox.get().strip()=="":
AttributeError: 'NoneType' object has no attribute 'get'
Các lỗi dấu vết trở lại Tkinter.py
.
Tôi chắc chắn một số người có thể đã xử lý vấn đề này trước đây. Bất kỳ trợ giúp được đánh giá cao.
Chi tiết khác [** tại đây **] (https://www.begueradj.com/tkinter-saya-idiom.html) –