Johnny Niklasson
Johnny Niklasson

Reputation: 127

Python Tkinter [Line seperator between buttons]

so recently i have gotten into Tkinter and been using the docs so far. I ran into this problem where make a visible seperator between my "toolbar buttons", example below:

Home | Insert | PC | Etc..

How could i go about making that seperator, becuase i tried ttk seperator but didnt help me.

Thanks in advance.

Upvotes: 0

Views: 1580

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385980

The ttk library has a Separator widget which is specifically designed for this. You can also use a frame with a width of 1 or two pixels.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
toolbar = tk.Frame(root)
toolbar.pack(side="top", fill="x", padx=20, pady=20)

button1 = tk.Button(toolbar, text="Home")
button2 = tk.Button(toolbar, text="Insert")
sep = ttk.Separator(toolbar)

button1.pack(side="left")
sep.pack(side="left", fill="y", padx=4, pady=4)
button2.pack(side="left")

root.mainloop()

enter image description here

Upvotes: 2

Related Questions