Giter VIP home page Giter VIP logo

pytkgen's Introduction

Create Tkinter GUIs from JSON definition files

The idea behind this simple module is that you can define Tkinter GUIs in a JSON file format. All value which can be configured for an widget can be defined in those files. The module 'tkgen' has an Generator class which is able to parse these files and return you a Tk root.

To use a JSON file as input:

root = tkgen.gengui.TkJson('ui.json', title = 'Some test gui...')
root.mainloop()

Please see the examples in the 'examples/' directory for more details on how to use this package.

Module can be retrieved from pypi as well:

easy_install/pip install pytkgen

Some useful Tips

So since the GUI itself is defined in a JSON file you need to lookup the widgets in your python code to do actual operations on them. The gengui module offers some routines which will make your life easy:

  • get(name) - Returns the Tkinter widget object of the widget with the given name. Requires that a name was indeed defined in the definition file for this widget. Now that you have the object for an Tkinter widget you can do everything which is defined for this particular widget with it using known techniques.

  • button(name, cmd, [...]) - Associates a 'Button' widget with a command - For example: 'root.destroy'.

  • checkbox(name, [...]) - Returns an 'IntVar' for a 'Checkbox' so you can retrieve the value (0/1) to see if the User checked the box or not.

  • entry(name, [...]) - Returns a 'StringVar' for a Entry so you can retrieve and set the value of a Entry widget.

  • label(name) - Returns a 'StringVar' for a Label so you can retrieve and set the value of a Label widget.

  • create_from_file([...]) - Create a set of widgets from a file and add them to a given parent widget.

  • notebook([...]) - Adds a tab to a tkk Notebook widget which is itself defined by a JSON file.

  • treeview([...]) - Adds a item to a given treeview.

  • toplevel([...]) - Creates a toplevel dialog from a JSON definition file.

  • create_menu([...]) - Create new menus, popup menus or submenus on the fly.

  • xscroll and yscroll([...]) - Adds a Horinzontal/Vertical Scrollbar to a widget.

Supported Attributes for Grid placement

On top of all attributes supported by a widget, the following attributes can be used in the JSON files to refine the placement of widgets in the Grid Geometry Manager:

  • row, column - Define the row and column in which the widget should appear (default: 0).

  • rowspan, columnspan - Define if the widget should span across multiple rows or columns (default: 1).

  • rowweight, colweight, weight - Define the weight for a row or column or both (weight). If the weight is set the parent rows/columns are configured automatically to take care of the resizing. (default: 0).

  • padx, pady - X,Y padding for the widget (default: 2px).

  • sticky - Defines the sticky attribute as string (default: 'news').

Changelog

1.5

  • Merged several cool contribs (e.g. ttk/tk preference & cleanups) from community
  • enabled it to work with python 2.* and 3.*

1.4

  • Support for sticky attribute in the JSON file

1.3

  • Code optimizations
  • Support for setting the focus of a widget
  • More 'supporting routines'

1.2

  • Support for creation of menus
  • Support for multiple frames in JSON
  • Support for ttk widgets (Treeview, Notebook, Separator, Progressbar, ...)
  • Resizing capabilities added (Weights can now be defined in the JSON file; 1 means the widget resize in general, rowweight=1 means it resize horizontal, colweight=1 means it resize vertical; Values > 1 mean that this widget will resize 'faster' (See Tk documentation for more information)).

1.1

  • Initial

Feel free to play around with this - I do not guarantee that it is perfect nor complete - Have Fun!

(c) 2011-2016 tmetsch

pytkgen's People

Contributors

giuliol avatar kicer avatar tmetsch avatar vedk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.