Viewable
Implement better Views for your Tkinter Python app
This project is part of the Pyrustic Open Ecosystem.
Overview
Views are the building blocks of your desktop application GUI. Viewable allows you to implement Views that are maintainable and easily extensible. Viewable defines a View in terms of its lifecycle. And so, you can split your source code to align with the main states a View goes through: init, build, map, and destroy.
Here's how to implement a View with Viewable:
import tkinter as tk
from viewable import Viewable
class View(Viewable):
def __init__(self, master):
super().__init__()
self._master = master
def _build(self):
"""
This is the only mandatory method to implement.
You define the body of the view here
"""
# the body is generally either
# a tk.Frame instance
# or a tk.Toplevel instance
self._body = tk.Frame(self._master)
label = tk.Label(self._body, text="Hello Friend !")
label.pack()
def _on_map(self):
""" This method is called when the view is mapped for the first time """
def _on_destroy(self):
""" This method is called when the view is destroyed """
# root
root = tk.Tk()
# the view
view = View(root)
# the method build_pack() builds then packs the view
# In fact you could do:
# view.build() then view.pack()
# or:
# view.build() then view.body.pack()
view.build_pack() # it accepts arguments like the Tkinter pack() method
# others ways to install a view:
# .build_grid(), .build_place(), .build_wait()
# you can access the body of the view via
# its .body property
view.body # here, the body is a tk.Frame
# To destroy a view, call the method .destroy()
view.destroy()
# The .state property reveals the state of the view:
# 'new', 'built', 'mapped', 'destroyed'.
print(view.state)
# mainloop
root.mainloop()
Installation
pip install viewable
Metadata
Release files for viewable 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| viewable-0.0.7.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| viewable-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.1 kB
Release files / viewable-0.0.7.tar.gz
| Download URL | viewable-0.0.7.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95e84d6fd6287a980a8370d7ce23df341e347cc3741fa73c1a11509fa77e9d3b
|
|
BLAKE2b-256 checksum How to use checksums |
2e76b7063ab0f425dccc16917d18d485b60848b7ba54bfa5b0361b0299fc6b0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.5.2
|
Release files / viewable-0.0.7-py3-none-any.whl
| Download URL | viewable-0.0.7-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86f80eda89d40431ee845981450f1e5a02820b3ac035b51eb1ef40039e0e6050
|
|
BLAKE2b-256 checksum How to use checksums |
c538ac805b93c33a695e08e43c5ab5a981d2a8f51bf8292356120472688b2ed5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.5.2
|