Python: Listbox without border Python: Listbox without border tkinter tkinter

Python: Listbox without border


You want to set the borderwidth to zero, but you also want to set highlightthickness to zero. Highlightthickness represents a rectangle that surrounds the whole widget when it has keyboard focus. Finally, when you use pack or grid, make sure you don't add any padding between them.

If you want to complete the illusion that the two widgets are one, put them in a frame and give the frame a borderwidth and relief.import Tkinter as tk

class Example(tk.Frame):    def __init__(self, parent):        tk.Frame.__init__(self, parent, borderwidth=1, relief="sunken")        lb1 = tk.Listbox(self, borderwidth=0, highlightthickness=0)        lb2 = tk.Listbox(self, borderwidth=0, highlightthickness=0)        lb1.pack(side="left", fill="both", expand=True)        lb2.pack(side="left", fill="both", expand=True)        lb1.insert(0, "left")        lb2.insert(0, "right")if __name__ == "__main__":    root = tk.Tk()    Example(root).pack(fill="both", expand=True, padx=8, pady=8)    root.mainloop()


I think the best you can achieve would be this:

import tkinter as tkroot = tk.Tk()wrapper = tk.Frame(root, bd=2, relief="sunken")L1 = tk.Listbox(wrapper, bd=0)L2 = tk.Listbox(wrapper, bd=0)L1.grid(column = 1, row = 1)L2.grid(column = 2, row = 1)wrapper.pack()root.mainloop()

note setting the border of each listbox to 0, (bd=0) and to give the overall widget a similar look to the original listbox i've wrapped it in a frame and given that the same border style as the default listbox.

also worth nothing that you need to get the bindings right to make them scroll as expected, just binding to the scroll wheel and scroll bar is insufficient as the lists can be moved with the arrow keys when an item is highlighted, like in the second example on this page:
scrolling multiple listboxes togetherby Santiclause


Speicfy borderwidth as 0 when you create a listbox.

For example:

from Tkinter import *  # from tkinter import *   (Python 3.x)root = Tk()lb = Listbox(borderwidth=0)  # <---lb.pack()root.mainloop()