Skip to content

Get started

Info

Tkinter expansion is python framework that expands tkinter with bunch of cool stuff.

Tkinter expansion is heavily inspired by JavaFX.

Contains

Feature Implemented
Designer ✅
Themes ✅
Hints ✅
RGB color ✅
Xml wrapper ❌ Security issue
Css wrapper ✅

tree structure of tkinter_expansion:

tkinter_expansion
├─ Classes
│  ├─ Designer
│  │  └─ Methods
│  │     ├─ load - argument: dict containing widgets to change their data
│  │     ├─ bind - bind widget to designer
│  │     ├─ bind_all - bind multiple widgets at once to designer
│  │     └─ set_theme_name - argument: theme_name
│  ├─ StyleManager
│  │  └─ Methods
│  │     ├─ load_css
│  │     └─ css_to_theme - argument: convert your css to theme
│  ├─ CssWrapperMissingFile
│  ├─ CssWrapperMissingChar
│  ├─ UnknownIdentifier
│  └─ DesignerThemeNotFound
└─ Functions
   ├─ identifiers
   ├─ bind_help - armugents: tkinter widget, help_text
   ├─ rgb_to_hex - arguments: red, geen, blue
   └─ hex_to_rgb - argmuent: hex color

News - Big and relax update!

Removed frustration from loading themes, fixed bugs, and much more! Everything is beautifuly on pypi

Installation

From pip

pip install tkinter_expansion

From source

git clone https://github.com/Fire-The-Fox/tkinter_expansion.git
cd tkinter_expansion
python setup.py install

Examples

Creating gui with Designer without themes

import tkinter as tk
import tkinter_expansion as tke

# App base

root = tk.Tk()
root.configure(width=700, height=700)

# Initializing Designer

# share_locals and share_globals free!
designer = tke.Designer(master=root)

# App widgets, please add name or just dont add it
window = tk.Button(root, name="window")
window.place(relx=0, rely=0, relheight=1, relwidth=1)

# Designer.show is set True by default.
# When you are done with designing just put show=False in tke.Designer()

designer.bind(window)

root.mainloop()

Creating gui with Designer with themes ( single widget theme - every widget has its own data )

import tkinter as tk
import tkinter_expansion as tke

# App base

root = tk.Tk()
root.configure(width=700, height=700)

# Initializing Designer

# share_locals and share_globals free!
designer = tke.Designer(master=root, share_locals=locals(), share_globals=globals())
designer.set_theme_name("theme_name") # or blank for default

# App widgets

# Ton of argument free!
window = tk.Button(root, name="window")
window.place(relx=0, rely=0, relheight=1, relwidth=1)

# Designer.show is set True by default.
# When you are done with designing just put show=False in tke.Designer()

designer.bind(window)

# loading theme

designer.load({"window": window})

root.mainloop()

Creating gui with Designer with themes ( more widgets have same data )

import tkinter as tk
import tkinter_expansion as tke

# App base

root = tk.Tk()
root.configure(width=700, height=700)

# Initializing Designer

# share_locals and share_globals free!
designer = tke.Designer(master=root, share_locals=locals(), share_globals=globals())
designer.set_theme_name("theme_name") # or blank for default

# App widgets

# Ton of argument free!
window = tk.Button(root, name="window")
window.place(relx=0, rely=0, relheight=1, relwidth=0.5)
window2 = tk.Button(root, name="window")
window2.place(relx=0.5, rely=0, relheight=1, relwidth=0.5)

# Designer.show is set True by default.
# When you are done with designing just put show=False in tke.Designer(), binding multiple widgets at once

designer.bind_all([window, windows2])

# loading theme

designer.load({"window": [window, window2]})

root.mainloop()

Converting rgb color to hex

import tkinter as tk
import tkinter_expansion as tke

[ code ]
window = tk.Button(root, bg=tke.rgb_to_hex(255, 7, 77))
window.place(relx=0, rely=0, relheight=1, relwidth=1)
[ code ]

Creating fully working hints

import tkitner_expansion as tke

root = tk.Tk()

widget = tk.Label(root)
widget.place(x=0, y=0, relwidth=1, relheight=1)
tke.bind_help(widget, "I am hint", 500)
root.mainloop()

Loading css as style

main.py

from tkinter_expansion import GuiStyle as Tks
import tkinter as tk

root = tk.Tk()
root.configure(width=700, height=700)

style = Tks.StyleManager(css_file="style.css") # initializing StyleManager
json_data = style.load_css() # load css data
style.css_to_theme("css") # convert css to theme

window = tk.Button(root, bg=json_data["window"]["color"],
                   activebackground=json_data["window"]["activebackground"],
                   highlightbackground=json_data["window"]["bordercolor"],
                   highlightthickness=json_data["window"]["bordercolorwidth"])
window.place(x=0, y=0, relwidth=0.5, relheight=1)

label = tk.Label(root, bg=json_data["label"]["background"])
label.place(relx=0.5, y=0, relwidth=0.5, relheight=1)
root.mainloop()

style.css

#window {
    color: #7d65ff;
    activebackground: #616644;
    bordercolor: #affabf;
    bordercolorwidth: 10;
}
#label {
    background: #9400D3;
}