I wanted to install the ttk libraries but it does not let me, the same to install Tkinter, try pip and did not find anything, I also tried to download them with Pycharm but it does not leave me anyway.
I'm trying with Python 2.7 and 3.6
I wanted to install the ttk libraries but it does not let me, the same to install Tkinter, try pip and did not find anything, I also tried to download them with Pycharm but it does not leave me anyway.
I'm trying with Python 2.7 and 3.6
As you have been told both Tkinter
and Ttk
are part of the standard Python library, therefore it does not make sense to try to use pip
to install it.
That said, the problem may be how to import them. In Python 2.x
Ttk
is an external module to Tkinter
while in Python 3.x
is part of the same package. To import it a very common way is:
Python 3.x:
import tkinter as tk
from tkinter import ttk
Python 2.x:
import Tkinter as tk
import ttk
Note that in Python 2.x
the module Tkinter
is capitalized and in Python 3.x
is lowercase.
This way, you do not overwrite the native Tkinter widgets with those of Ttk, making the code much more readable by always explaining which toolkit you are using at any time.
An example of use:
Python 3.x:
import tkinter as tk
from tkinter import ttk
master = tk.Tk()
def callback1():
print ("Click en el boton de tkinter")
def callback2():
print ("Click en el boton de ttk")
boton1 = tk.Button(master, text="Tkinter", command=callback1)
boton2 = ttk.Button(master, text="ttk", command=callback2)
boton1.pack()
boton2.pack()
master.mainloop()
Python 2.x:
import Tkinter as tk
import ttk
master = tk.Tk()
def callback1():
print ("Click en el boton de tkinter")
def callback2():
print ("Click en el boton de ttk")
boton1 = tk.Button(master, text="Tkinter", command=callback1)
boton2 = ttk.Button(master, text="ttk", command=callback2)
boton1.pack()
boton2.pack()
master.mainloop()
boton1
is a native button of Tkinter
while boton2
is an 'enhanced' button of extension Ttk
.
You can see more about Tkinter and its use in the official documentation of Python.
If these codes give you an error edit the question and provide the error that marks you, the code you use and how to import the modules so we can help you better.