Package: guitk
Python GUI Toolkit for TK (GUITk)SynopsisGUITk is a declarative framework for building nice-looking, cross-platform GUIs withtkinterinspired bySwiftUI.GUITk allows you to build complete GUI applications with a few lines of code. GUITk makes it easy to layout your GUI elements and respond to events using a declarative syntax. Because GUITk is built on top of tkinter, you can access the underlying tkinter API if you need to but for many use cases, you can build your GUI without needing to know much about tkinter.GUITk apps are built by subclasses theguitk.Windowclass. Your GUI elements are layed out using aguitk.HLayout(horizontal layout) orguitk.VLayout(vertical layout) object which takes care of placing all widgets in the window using a declarative syntax. This is much simpler than using the underlying tkintergrid managerorpackgeometry managers.GUITk is in alpha stage but is in constant development so check back frequently if this interests you or open an issue to start a conversation about what pain points this project could help you solve!Documentation is available atGUITk.Code ExampleSimple HLayout"""Simple Hello World example using guitk """importguitkasui# subclass guitk.Window as the starting point for your app's main windowclassHelloWindow(ui.Window):defconfig(self):"""Configure the window"""# set the window titleself.title="Hello, World"# define a layout for the window# the layout manager will automatically add widgets to the windowwithui.HLayout():ui.Label("What's your name?")ui.Entry(key="name",focus=True)ui.Button("Ok")@ui.on(key="Ok")defon_ok(self,event:ui.Event):"""Handle the Ok button click"""print("Hello, ",self.get("name").value)# run your event loopif__name__=="__main__":HelloWindow().run()MotivationThe goal of GUITk is to make it very easy to create simple and attractive GUI apps with python. It borrows ideas from several other libraries includePySimpleGUI,SwiftUI,textual, andapplepy. GUITk builds ontkinterwhich ships with the Python standard library and works across many platforms. tkinter is a mature and powerful GUI framework but requires a fair bit of boiler plate and understanding of the underlying framework to use effectively. GUITk attempts to simplify this by providing a higher level interface to tkinter while still allowing you to access the underlying tkinter API if you need to.Though you can build simple apps without knowing much about tkinter, GUITk is not intended to fully abstract away the tkinter interface. A basic understanding of tkinter will be helpful when building with GUITk. I highly recommend Mark Roseman's excellentModern Tkinter for Busy Python Developersbook as a starting point.Installationpython3 -m pip install guitkAnatomy of a guitk program"""Hello World example using guitk """importguitkasuiclassHelloWorld(ui.Window):# subclass guitk.Window as the starting point for your app's main windowdefconfig(self):# Your Window class needs to define a config() method that describes the layout, title, etc for your app# config() is called by the Window class when the Window is being created# Title for the windowself.title="Hello, World"# optionally set size as a tuple of (width, height)self.size=(320,240)# you can also use self.geometry for consistency with tkinter# self.geometry = "320x240"# Define the window's contents# guitk.Label corresponds to a tkinter.ttk.Label, etc.# optionally provide a unique key to each element to easily reference the element later# use a HLayout or VLayout class to define the layout of the window# HLayout arranges widgets horizontally, VLayout arranges widgets verticallywithui.VLayout():# use a VLayout to stack the widgets vertically# standard tkinter layout options such as sticky and weight are supportedui.Label("What's your name?",sticky="ew",anchor="center",weightx=1)# each widget can be assigned a key, which should be unique, to easily reference the widget later# set focus=True so the Entry box has focus when the window is displayedui.Entry(key="entry_name",focus=True,weightx=1,sticky="ew")ui.Label("",width=40,key="output")withui.HStack():# align these two buttons in a horizontal row using HStackui.Button("Ok")ui.Button("Quit")# Every Window class has 3 special methods that can be overridden to provide custom behavior# you do not need to provide any of these methods if you do not need to customize the default behavior# (the default behavior is to do nothing)# These special methods are: setup(), teardown(), and handle_event()defsetup(self):"""Perform any initialization needed before the Window is displayed"""# your setup() method is called by the Window class after config() just before the Window is displayed# use this to initialize any internal state you need# you do not need to provide a setup() method if no initialization is neededprint("setup")defteardown(self):"""Perform any cleanup needed before destroying the window"""# your teardown() method is called by the Window class after the Window is closed# use this to clean up before the Window is destroyed# you do not need to provide a teardown() method if no cleanup is neededprint("teardown")defhandle_event(self,event:ui.Event):"""handle_event() is called by the Window class when an event occurs"""# you do not need to provide a handle_event() method if you prefer to use# the @on decorator to bind functions to events (see below)# handle_event() is a useful place to put code that needs to run for every event# or for use during debuggingprint(f"handle_event:{event}")@ui.on(key="Quit")defon_quit(self):# return the value of the Entry boxself.quit(self["entry_name"].value)@ui.on(key="Ok")@ui.on(event_type=ui.EventType.EntryReturn)defon_ok(self):# User pressed the OK button or the Return key inside the Entry box# the @on decorator can be used to bind a function to an event# @on can be repeated to bind the function to multiple events# set the output Label to the value of the Entry box# individual widgets can be accessed by their key; the window object acts as a dictionary of widgetsgreeting=f"Hello{self['entry_name'].value}! Thanks for trying guitk."# if you prefer, you can use get() instead of the dictionary syntaxself.get("output").value=greetingif__name__=="__main__":# instantiate your Window class and run itname=HelloWorld().run()print(f"Hello{name}")DocumentationNot much documentation at this point but there's a starthere.  Take a look at theexamplesdirectory for a number of self-documenting examples on use of various widgets.TestingThere are currently no automated tests as I haven't figured out how to do these with tkinter. I am working on adding tests and there are several tests that run withpytestin thetestsdirectory.  These are not automated and require user interaction.You can also runpython3 -m guitkwhich opens a window with examples of all the widgets. I find this useful for quick testing of layout and widget behavior.ContributorsContributions welcome! If this project interests you, open an Issue or send a PR!TODOBasic prototypeFrameLabelEntryButtonCheckbuttonRadiobuttonTextScrolledTextTreeviewListboxComboboxSpinnerOther widgetsMenusTooltipsDocumentationAdd docstringsAdd type hints to public APITestsLicenseLicensed under the MIT License.See AlsoTextual- An amazing Python framework for building user interfaces in the terminal.PySimpleGUI- A Python GUI Framework.applepy- A declarative GUI framework for developing native macOS applications in Python 3.