如何在选择GUI时删除黑色边框?

时间:2015-03-20 16:05:49

标签: python tkinter

我正在尝试使用EntryFrame添加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时出现的黑色边框?

1 个答案:

答案 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()