我正在尝试使用Entry
向Frame
添加Scrollbar
窗口小部件。当我点击GUI时,会出现黑色边框:
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时出现的黑色边框?
答案 0 :(得分:2)
要删除小部件的边框(例如Text
窗口小部件),请将highlightthickness
属性设置为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()