I'm trying to create a vertical line between two columns using tkinter grid. I have been looking for ways to do it, but it's all something that I don't need like coordinates.
from tkinter import *
master = Tk()
player1 = "A"
player2 = "B"
from tkinter import *
Label(master, text="NAME", font=30).grid(row=0)
Label(master, text=player1, font=30).grid(row=1)
Label(master, text=player2, font=30).grid(row=2)
Label(master, text="SCORE", font=30).grid(column=2, row=0)
I want to add a vertical line at column 1, is there a way to do that?
You can use a ttk.Separator
widget.
Add the following to your code:
import tkinter.ttk
tkinter.ttk.Separator(master, orient=VERTICAL).grid(column=1, row=0, rowspan=3, sticky='ns')
Here rowspan=3
is necessary to make the separator span all 3 rows (the header, player 1 and player2). The sticky='ns'
is there to stretch the separator from the top to the bottom of the window. Separators are only 1 pixel long per default, so without the sticky
it would hardly be visible.
Preview of the result:
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