Skip to main content

Class to implement a GUI view with lifecycle

Project description

Figure

Viewable

Implement better Views for your Tkinter Python app

This project is part of the Pyrustic Open Ecosystem.

Installation | Reference

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.4.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

viewable-0.0.4-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file viewable-0.0.4.tar.gz.

File metadata

  • Download URL: viewable-0.0.4.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

Hashes for viewable-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e39e341be63e853b7c1abcba69100e31329b0c74af3533738fd8836c1c249f4c
MD5 bee2a77b1cbc45795e08137850e0d6dc
BLAKE2b-256 2c24939004b2712638babdc66deb743154939b7448a68b2f8a8eadbcd3ba23f4

See more details on using hashes here.

File details

Details for the file viewable-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: viewable-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.3 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

Hashes for viewable-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8eba06529a60ec8af3b5de56f0846ef73b0b7a4437b3f9121557893ac3ff7c12
MD5 e181d83b81e043685cc46a5c9c4d4fbe
BLAKE2b-256 6f6fd32aab3a2df2fa3213b57ee90e95967fa4ddaa63924138815f40fb79fe0f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page