Reputation: 109
Trying to use Treeview in a project but just got hit with an error; module 'tkinter' has no attribute 'Treeview'
Here's my code;
import tkinter as tk
from tkinter import *
import tkinter as ttk
class MainGUI:
def __init__(self, master):
self.master = master
self.EmpInfo = ttk.Treeview(self.master).grid(row = 1 , column = 1)
def main():
root = tk.Tk()
a = MainGUI(root)
root.mainloop()
if __name__ == '__main__':
main()
Do i need to pip install more stuff or am i just using Treeview wrong?
Upvotes: 4
Views: 6933
Reputation: 359
Why are you doing this?
import tkinter as tk
from tkinter import *
import tkinter as ttk
You first import tkinter as tk
, then import the entire library, then import the library again but this time as ttk
.
So either import the library as a whole with *
. Or choose an alias such as tk
.
Additionnaly, I think you should try from tkinter import ttk
and then call ttk.Treeview
.
Be careful next time ;)
Upvotes: 0
Reputation: 386362
You are using Treeview
wrong. It's in the ttk module. You need to import ttk, and then use Treeview
from the ttk module
from tkinter import ttk
...
self.EmpInfo = ttk.Treeview(...)
...
Upvotes: 7