當我嘗試將焦點設置在條目小部件上時,我收到錯誤消息,Traceback (most recent call last): File "C:/PythonPrograms/Tkinter/test_case.py", line 13, in <module> entSearch.focus()AttributeError: 'NoneType' object has no attribute 'focus'通過在堆棧溢出時搜索此錯誤的其他出現,修復似乎是在單獨的行上調用 grid 方法。entSearch = Entry(main, textvariable = text, width = 50, font='arial 12')entSearch = entSearch.grid(row = 0, column = 1, sticky=W)而不是entSearch = Entry(main, textvariable = text, width = 50, font='arial 12').grid(row = 0, column = 1, sticky=W)不幸的是,此修復程序對我不起作用。from tkinter import *main = Tk()main.title("Test Case")main.geometry('750x750')main.configure(background='ivory3')text = StringVar()entSearch = Entry(main, textvariable = text, width = 50, font='arial 12')entSearch = entSearch.grid(row = 0, column = 1, sticky=W)entSearch.focus()main.mainloop()預期,當代碼運行時,Entry Widget 將成為焦點。但相反,我收到了錯誤Traceback (most recent call last): File "C:/PythonPrograms/Tkinter/test_case.py", line 13, in <module> entSearch.focus()AttributeError: 'NoneType' object has no attribute 'focus'
添加回答
舉報
0/150
提交
取消