sqlite Why Tree未定义但已经导入tkinter & tkinter.ttk python

5vf7fwbs  于 2023-06-30  发布在  SQLite
关注(0)|答案(1)|浏览(125)

我想问为什么树是未定义的,但我已经import tkintertkinter ttk我怎么能解决这个问题?

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()
jdzmm42g

jdzmm42g1#

使用相同的更改定义树视图:

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()

相关问题