Tkinter vs TTK (better widgets)

Ttk?

Tkinter has another submodule that makes the widgets way cooler than the main one. In the next picture you can see some radiobuttons with tkinter and tkinter.ttk, to see the difference.

Tkinter version

# the code
# for the original tkinter

import tkinter as tk


root = tk.Tk()

vstring = tk.IntVar()

text_value = [
    ("option 1", "1"),
    ("option 2", "2"),
    ("option 3", "3"),
    ("option 4", "4")
]

for t, v in text_value:
    r = tk.Radiobutton(root)
    r['text'] = t
    r['value'] = v
    r['variable'] = vstring
    r.pack(anchor=tk.W)

root. mainloop()

Tkinter.ttk version

# the version for
# tkinter.ttk

import tkinter
import tkinter.ttk as tk


root = tkinter.Tk()

vstring = tkinter.IntVar()

text_value = [
    ("option 1", "1"),
    ("option 2", "2"),
    ("option 3", "3"),
    ("option 4", "4")
]

for t, v in text_value:
    r = tk.Radiobutton(root)
    r['text'] = t
    r['value'] = v
    r['variable'] = vstring
    r.pack(anchor=tkinter.W)

root. mainloop()

Tkinter test for students

Tkinter articles

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.