Class to implement a GUI view with lifecycle
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
viewable-0.0.5.tar.gz
(8.4 kB
view details)
Built Distribution
viewable-0.0.5-py3-none-any.whl
(14.5 kB
view details)
File details
Details for the file viewable-0.0.5.tar.gz
.
File metadata
- Download URL: viewable-0.0.5.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a71a7718d0dbdf45c1f1e87d51beb48ac8acb98c9735a6219bb29bc9a3af2734 |
|
MD5 | 4ae8f31632310e73bac7e4adf35da94f |
|
BLAKE2b-256 | 48707838d62ebcbdc670995eee53532b6263ff088df007b3bd11d5bfcbb2d3f8 |
File details
Details for the file viewable-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: viewable-0.0.5-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b05c0d32325d055eac0fbb6cf94a379e8d962535b73bf20a4717a457d596a73 |
|
MD5 | 68b920251e169bf5a683ddce1442cfa6 |
|
BLAKE2b-256 | e30e8ebeb0027d70e5f122355e7b145f4cf9955cc7afdc4cf418b77713e6c8a8 |