tkup 1.2.0

Creator: bradpython12

Last updated:

Add to Cart

Description:

tkup 1.2.0

# tkuptkup is a thin wrapper around standard Tkinter widgets, allowing you to writecode that visually reflects the widget hierarchy. It doesn't try to reinventthe wheel and just helps you use normal Tkinter in a streamlined way.Typical Tkinter code is flat, even though it represents a heavily nestedstructure, which makes it difficult to quickly read and understand the trueorganization of the GUI. You must also explicitly assign each widget's master,which is error-prone and verbose:```pythonimport tkinter as tkfrom tkinter import ttkapp = tk.Tk()app.title = "Demo"outer_frame = ttk.Frame(app)outer_frame.grid()hi_button = ttk.Button(outer_frame, text="hi")hi_button.grid()app.mainloop()```tkup solves this by using nested with-statements. There are factory functionsfor each kind of widget, and you can use them as context managers so thatnested master widgets are automatically assigned. Post-instantiation calls,like gridding, can be accomplished two ways, most traditionally by naming theyielded value:```pythonfrom tkup import GUIapp = GUI()with app.root() as root: root.title = "Demo" with app.frame() as outer_frame: outer_frame.grid() with app.button(text="hi") as hi_button: hi_button.grid()app.run()```However, naming every single widget just to grid it can be tiresome.Inspired by Kotlin's implicit creation of the `it` variable in lambdas,the GUI class provides an `it` method which returns the current master widget,and there is an additional convenience method called `with_it` which returnsthe GUI instance and its `it` method for quick assignment to variables:```pythonfrom tkup import GUIapp, it = GUI().with_it()with app.root(): it().title = "Demo" with app.frame(): it().grid() with app.button(text="hi"): it().grid()app.run()```tkup prefers themed (ttk) widgets wherever available. If you want to useclassic widgets, or if you want to use a custom subclass of `tkinter.Widget`,then you can use the GUI `widget` method and pass in the type to instantiate:```pythonimport tkinter as tkfrom tkup import GUIapp = GUI()with app.root(): with app.widget(tk.Button, text="foo"): ...```## Installation```pip install tkup```tkup supports Python 3.5 and higher.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.