选择GUI时如何去除黑色边框? [英] How to remove black border when GUI is selected?
本文介绍了选择GUI时如何去除黑色边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Scrollbar
将 Entry
小部件添加到 Frame
.当我单击 GUI 时,出现黑色边框:
I am trying to add an Entry
widget to a Frame
with a Scrollbar
. When I click on the GUI, a black border appears:
import Tkinter as tk
class Example(tk.Frame):
def __init__(self, root):
tk.Frame.__init__(self, root)
self.canvas = tk.Canvas(root)
self.frame = tk.Frame(self.canvas)
self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((4,4), window=self.frame, anchor="nw",
tags="self.frame")
self.frame.bind("<Configure>", self.OnFrameConfigure)
self.addEntry()
def addEntry(self):
self.entryVariable = tk.StringVar()
self.entry = tk.Entry(self.frame,textvariable=self.entryVariable)
self.entry.grid(column=0,row=0,sticky='EW')
self.entryVariable.set(u"")
self.entry.focus_set()
self.entry.selection_range(0, tk.END)
def OnFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
if __name__ == "__main__":
root=tk.Tk()
Example(root).pack(side="top", fill="both", expand=True)
root.mainloop()
如何去除选择GUI时出现的这个黑色边框?
How to remove this black border that appears when GUI is selected?
推荐答案
要移除小部件的边框(例如 Text
小部件),请设置 highlightthickness
属性到 0
.
To remove the border of your widgets (for example of a Text
widget) set the highlightthickness
attribute to 0
.
这里有一个工作示例:
import tkinter as tk
class Example(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.text = tk.Text(self, highlightthickness=0)
self.text.pack(expand=1, fill='both')
root = tk.Tk()
Example(root).pack(expand=1, fill='both')
root.mainloop()
这篇关于选择GUI时如何去除黑色边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文