-2

I want to ask why the tree is undefined but I already import tkinter and tkinter ttk how can I solve this?

from tkinter import *
from tkinter.ttk import *
from PIL import Image, ImageTk
import sqlite3


def ListMahasiswa():
    root = Tk()
    root.geometry('400x40')
    root.title("My Test GUI")

    connect = sqlite3.connect('Presensi.db')
    cur = connect.cursor()
    cur.execute("Select * FROM presensi")
    fetch = cur.fetchall()
    for data in fetch:
       tree.insert('', 'end', values=(data[1], data[2], data[3]))    

    connect.commit()
    cur.close()

    

    root.mainloop()
toyota Supra
  • 3,181
  • 4
  • 15
  • 19
  • ***why the tree is undefined***: You didn't show or never define `tree = ?` – stovfl May 25 '20 at 20:41
  • Does this answer your question? [does-tkinter-have-a-table-widget](https://stackoverflow.com/questions/9348264) – stovfl May 25 '20 at 20:45

1 Answers1

0

Define your treeview with same changes:

def ListMahasiswa():
    root = Tk()
    root.geometry('400x300+500+100')
    root.title("My Test GUI")
    cols=['col1','col2','col3']
    tree = ttk.Treeview(root, columns=cols, show='headings')
    connect = sqlite3.connect('Presensi.db')
    cur = connect.cursor()
    cur.execute("Select * FROM presensi")
    fetch = cur.fetchall()

    for data in fetch:
       tree.insert('', 'end', values=(data[1], data[2], data[3]))    
    for col in cols:
        tree.heading(col, text=col)
        tree.column(col, width=100)
    connect.commit()
    cur.close()
    tree.pack()

    root.mainloop()
Alchimie
  • 426
  • 4
  • 12