insolor / tkinter-layout-helpers

A library which is intended to simplify a placement of widgets with .grid() and .pack() methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tkinter Layout Helpers

Python package Coverage Status PyPI Supported Python versions

A library which is intended to simplify a placement of widgets with .grid() and .pack() methods:

  • avoid manual calculation of indices of columns and rows when you add a widget;
  • avoid typing-in some common parameters (like sticky=tk.EW) each time you add a widget;
  • and more...

Work in progress.

As an example, this code:

import tkinter as tk
from tkinter_layout_helpers.grid_helper import grid_manager

root = tk.Tk()

with grid_manager(root, sticky=tk.EW) as grid:
    grid.new_row() \
        .add(tk.Label(text="0", width=20)) \
        .add(tk.Label(text="1", width=20)) \
        .add(tk.Label(text="2", width=20)) \
        .add(tk.Label(text="3", width=20)) \
        .add(tk.Label(text="4", width=20))

    grid.new_row().add(tk.Entry()).column_span(4).add(tk.Entry()).column_span(1)
    grid.new_row().add(tk.Entry()).column_span(3).add(tk.Entry()).column_span(2)
    grid.new_row().add(tk.Entry()).column_span(2).add(tk.Entry()).column_span(3)
    grid.new_row().add(tk.Entry()).column_span(1).add(tk.Entry()).column_span(4)

    grid.columnconfigure(0, weight=1)
    grid.columnconfigure(1, weight=1)
    grid.columnconfigure(2, weight=1)
    grid.columnconfigure(3, weight=1)
    grid.columnconfigure(4, weight=1)

root.mainloop()

Gives the following result:

image

More examples see here: examples

About

A library which is intended to simplify a placement of widgets with .grid() and .pack() methods

License:MIT License


Languages

Language:Python 100.0%