【问题标题】:How to remove black border when GUI is selected?选择 GUI 时如何去除黑边?
【发布时间】:2015-03-20 16:05:49
【问题描述】:

我正在尝试使用ScrollbarEntry 小部件添加到Frame。当我点击 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时出现的黑色边框?

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    要删除小部件(例如 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多