Irena Jodeikiene Irena Jodeikiene - 3 months ago 31x
Python Question

Drawing on Tkinter grid

I couldn't find a way how to Draw line using grid. I want to have a line going from North to South seperating left and right frames.

self.left= Frame(, bg="black")
self.left.grid(column=0, row = 0, pady=5 ,padx=10, sticky=N) = Frame ( ,bg= "black"), row = 0, pady=5,padx=10, sticky=N)

self.right= Frame(, bg="black")
self.right.grid(column=2, row = 0, pady=5,padx=10, sticky=N)

I want something like

self.w.create_rectangle(self.centerwidth/2-2, 0, centerwidth/2+2, self.windowheigh, fill="#00CC00", outline = "#00CC00")


If you want to separate the left frame from the right one, you can use a separator from ttk module (

Here is an example:

# python3
import tkinter as tk
from tkinter.ttk import Separator, Style

# for python2 : 
# import Tkinter as tk
# from ttk import Separator

fen = tk.Tk()

left = tk.Frame(fen, bg="black",width=100, height=100)
# to prevent the frame from adapting to its content :
tk.Label(left, text="Left frame", fg="white", bg="black", anchor="center", justify="center").pack()
left.grid(column=0, row = 0, pady=5 ,padx=10, sticky="n")
sep = Separator(fen, orient="vertical")
sep.grid(column=1, row=0, sticky="ns")

# edit: To change the color of the separator, you need to use a style
sty = Style(fen)
sty.configure("TSeparator", background="red")

right= tk.Frame(fen, bg="black",width=100, height=100)
tk.Label(right, text="Right frame", fg="white", bg="black").pack()
right.grid(column=2, row = 0, pady=5,padx=10, sticky="n")