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()
How to remove this black border that appears when GUI is selected?
To remove the border of your widgets (for example of a Text widget) set the highlightthickness attribute to 0.
Here, you have a working example:
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With