sujit sujit - 7 months ago 67
Python Question

why does tkinter ttk showing "name ttk is not defined" in python 3.5.1

Consider this simple code:

from tkinter import *
from tkinter.ttk import *
root= Tk()
ttk.Label(root, text='Heading Here').grid(row=1, column=1)
ttk.Separator(root,orient=HORIZONTAL).grid(row=2, columnspan=5)
root.mainloop()


when i run this code it's showing error

ttk.Label(root, text='Heading Here').grid(row=1, column=1)
NameError: name 'ttk' is not defined

Answer
ttk.Label(root, text='HeadingHere').grid(row=1, column=1) 
NameError: name 'ttk' is not defined
In this remove ttk as follows.    
Label(root, text='HeadingHere').grid(row=1, column=1

Now it works fine

Comments