0

Hi everybody.
How can i install ttk module on linux?
When i try to import and use it on my Tkinter window, the error says sth like there is no module named ttk. So it means i should install it right?! I'm using python 2. I want to use ttk to make buttons more nicely.

4
Contributors
7
Replies
45
Views
2 Years
Discussion Span
Last Post by Gribouillis
Featured Replies
2

In python 2 in kubuntu, I can import it directly

import ttk

In python 3 it is

from tkinter import ttk

ttk.py should be in the folder lib-tk in your python2 library. Try to run

locate ttk

in a terminal to see where it is.

0

This is a simple example:

from Tkinter import ttk

window = Ttk()
button = ttk.Button(window, text='hi')
button.pack()
window.mainloop()

Ande the error:

Traceback (most recent call last):
  File "ttk.py", line 1, in <module>
    from Tkinter import ttk
ImportError: cannot import name ttk
0

Simply cover both Python2 and Python3:

try:
    # Python2
    import Tkinter as tk
    import ttk
except ImportError:
    # Python3
    import tkinter as tk
    import tkinter.ttk as ttk

window = tk.Tk()
button = ttk.Button(window, text='hi')
button.pack()
window.mainloop()
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.