Skip to main content

No project description provided

Project description

tkx (tkinter (e)xtension) *

tkx (pronounced "tics") is a GUI library built on top of tkinter with the intention of minimizing pain while setting up user interfaces. As it stands, tkx is heavily under development and it could be quite a while before it reaches maturity.

One of the first ideas in the conception of tkx was implementing support for CSS, the straightforward syntax of which would make styling tkinter widgets far less painful and verbose. This will also allow developers to separate visual styles from logic.

As it stands, tkx doesn't change much. Here are two code examples with identical output:

Without tkx

import tkinter as tk


def main():
    # Create a window.
    root = tk.Tk()
    root.title("Hello, World!")
    root.pack_propagate(0)

    # Add some text.
    tk.Label(root, text="This is some text.").pack()

    # Run the application.
    root.mainloop()


if __name__ == "__main__":
    main()

Note: root.pack_propagate(0) is used to prevent the window from resizing to match the size of the tk.Label object. This is the default behavior in tkx, as shown below.

With tkx

import tkinter as tk
import tkx


def main():
    # Create a window.
    root = tkx.Window("Hello, World!")

    # Add some text.
    root.add(tk.Label, text="This is some text.")

    # Run the application.
    root.mainloop()


if __name__ == "__main__":
    main()

On Windows systems, both programs above will output a window resembling the following:

Standard tkinter window with bright background and black text

CSS Stylesheets

All it takes to style elements with tkx is a CSS file and a Stylesheet object. Consider the following code:

import tkinter as tk
import tkx


def main():
    # Define a stylesheet and main window.
    stylesheet = tkx.Stylesheet("./main.css")
    root = tkx.Window("Test!", stylesheet)

    # Add a button and give it some functionality.
    btn = root.add(tk.Button, text="Click me!")
    btn.bind("<Button-1>", lambda _: print("Hello, World!"))

    # Add some text.
    root.add(tk.Label, text="This is text!")
    root.add(tk.Label, text="This is some more text!")

    root.mainloop()


if __name__ == "__main__":
    main()

And the following CSS stylesheet:

/* main.css */

:root {
    --bg: #333;
    --fg: #ddd;
    --blue: #0ac;
}

Window {
    background: var(--bg);
    width: 300;
    height: 120;
}

Button {
    background: var(--blue);
    border-style: flat;
    color: black;
}

Label {
    background: var(--bg);
    border-style: flat;
    border-width: 2;
    color: var(--fg);
}

The above code outputs the following:

Dark gray window with a blue button and white text

* Name is subject to change.

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

tkx-0.1.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

tkx-0.1.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file tkx-0.1.1.tar.gz.

File metadata

  • Download URL: tkx-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Windows/10

File hashes

Hashes for tkx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1844579a31692a5fe5361d9e109b3d9bea468f615bc3553e6627ef7b5307c111
MD5 6e9578398a8ad332af6d3a5abc3df1cd
BLAKE2b-256 043cbb7bd396a26482997205f9c6aa86bc4962e58dfe45d8f2d6a46291a9b97c

See more details on using hashes here.

File details

Details for the file tkx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tkx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Windows/10

File hashes

Hashes for tkx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 089bd85c9bc34b61493ca032378363b9551effc62b72d7119c4b9575335ecdb2
MD5 3f6dad01b4fe7769c7909b11980b93ab
BLAKE2b-256 343f91fe9c2b58b6a47d69570ef54491d7a3d331807a54ddaca81e4df3697238

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