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.

Recommended Answers

All 7 Replies

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.

ttk is included with Python27 on Debian Linux.
What is your exact traceback error message?

This is a simple example:

from Tkinter import ttk

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

Ande the error:

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

In python 2, use

import ttk

why don't you read the answers ?

Simply cover both Python2 and Python3:

    # 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')

There is no such thing as
window = Ttk()
window = ttk.Tk()

That's many t's and k's.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.