Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertical line tkinter using grid

Tags:

python

tkinter

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?

like image 727
toto1105 Avatar asked Apr 01 '18 13:04

toto1105


1 Answers

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:

Preview

like image 85
Aran-Fey Avatar answered Oct 09 '22 07:10

Aran-Fey