Dav*_*ews 1 python tkinter python-3.x
当我尝试将焦点设置在条目小部件上时,我收到错误,
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'
Run Code Online (Sandbox Code Playgroud)
通过在堆栈溢出上搜索此错误的其他出现情况,修复似乎是在单独的行上调用网格方法。
entSearch = Entry(main, textvariable = text, width = 50, font='arial 12')
entSearch = entSearch.grid(row = 0, column = 1, sticky=W)
Run Code Online (Sandbox Code Playgroud)
而不是
entSearch = Entry(main,
textvariable = text,
width = 50,
font='arial 12').grid(row = 0, column = 1, sticky=W)
Run Code Online (Sandbox Code Playgroud)
不幸的是这个修复对我不起作用。
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()
Run Code Online (Sandbox Code Playgroud)
预计,当代码运行时,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'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1385 次 |
| 最近记录: |