我在类似的错误消息上看到了其他一些帖子,但找不到可以解决我的问题的解决方案.
我用TkInter稍微涉足并创建了一个非常简单的UI.该守则如下─
from tkinter import *
root = Tk()
def grabText(event):
print(entryBox.get())
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()
Run Code Online (Sandbox Code Playgroud)
我启动并运行UI.当我单击Grab按钮时,我在控制台上收到以下错误:
C:\Python> python.exe myFiles\testBed.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python\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'
Run Code Online (Sandbox Code Playgroud)
错误追溯到entryBox.
我敢肯定有人可能以前处理过这个问题.任何帮助表示赞赏.
我将使用表示URL的标签列表填充框架.网址将从列表中输入,数量可以在3到5之间,由用户决定.使这些网址可点击的最简单方法是什么,以便用户可以访问显示的网站?有没有比使用标签更好的方法呢?
谢谢
如何更改文本相对于 Tkinter 复选框的位置Checkbutton?
默认情况下,文本位于复选框的右侧。我想更改它,因此文本位于复选框的左侧或上方。
我知道这可以通过创建一个Label包含所需文本的文本并将两者巧妙地放置在彼此附近来完成,但我宁愿避免这种方法。
一些示例代码:
from Tkinter import *
root = Tk()
Checkbutton(root, text="checkButon Text").grid()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)