tkinter小工具周围的灰色边框(不使用画布)

1 人关注

我正在做的一个Python 3 tkinter程序遇到了问题。

我正在运行macOS Sierra。

当运行应用程序时,每个小组件周围都有一个灰色的边框。

有什么办法可以去除这个吗?

Screenshot of the border:

Here's the code:

# Item list
itemlist=Treeview(root)
itemlist.heading("#0", text="Item Name")
itemlist["columns"]=("1")
itemlist.column("1",width=50)
itemlist.heading("1",text="Item ID")
itemlist.bind("<Double-1>", select)
itemlist.grid(row=2,column=1,padx=10,pady=10)
# Nametag
Label(root,text="Name:").grid(row=3,column=0)
# 'Save' Button
saveButton=Button(text="Save")
saveButton.bind("<Button-1>",savebind)
saveButton.grid(row=1,column=0)
# 'Add New' button
newItemButton=Button(text="New Event")
newItemButton.bind("<Button-1>",newItem)
newItemButton.grid(row=0,column=1)
# Name entry text field
itemNameEntry=Entry(root,width=25)
itemNameEntry.grid(row=3,column=1)
# Submit Button
submitButton=Button(root,width=25,text="Submit")
submitButton.grid(row=4,column=1)
submitButton.bind("<Button-1>",submit)
# Begin loading
load()
# Start GUI
root.mainloop()
    
5 个评论
将小组件的实际背景属性设置为与你的画布背景相同的颜色,这不是一个很好的解决办法,但它是有效的。
这在一个答案中已经提到过了。不幸的是,这并不奏效。
所提到的答案 highlightbackground 尝试只是 background
同样的结果 _tkinter.TclError: unknown option "-background"
不要用冲锋枪
python
macos
tkinter
user7450368
发布于 2017-02-27
3 个回答
Luke.py
Luke.py
发布于 2020-03-24
已采纳
0 人赞同

将你的部件配置为使用 highlightbackground = 'white' (或任何你的背景颜色)并设置你的 highlightthickness=0

This should remove the grey outline.

itemNameEntry=Entry(root,width=25, highlightbackground='white')
itemNameEntry.config(highlightthickness=0)
    
I get _tkinter.TclError: unknown option "-highlightbackground" and _tkinter.TclError: unknown option "-highlightthickness" when running.
不幸的是,没有 :(
看起来它是一个Mac问题。 stackoverflow.com/questions/27084321/...
我认为它们是分开的,颜色看起来不同。
你是在比较两种不同类型的小工具吗?
gcx11
gcx11
发布于 2020-03-24
0 人赞同

你可以使用widget.config(highlightthickness=0)或者在widget构造函数中传递这个参数。