我有一个大问题。我创建了一个sql文件来记录一些数据,我需要将其显示到我的python程序中,我通过将所有数据放在variuos标签中来做到了这一点,但是如果数据太多,它就不会显示最新注册的数据。如何使用滚动条将所有标签放入容器中? 这是我有较少数据:https://imgur.com/c5wQnao时得到的结果,而这是我有许多数据:https://imgur.com/HaySYMI时得到的结果。
我试图将所有项目放在一个列表框中,但是按钮的显示方式很糟糕:(。
import sqlite3
from tkinter import *
def visualizza():
i = 0
c.execute('SELECT data FROM contabilita')
for row1 in c.fetchall():
i += 1
lblsql = Label(root, text=row1, width=15, bg = 'white', padx=5, pady=5)
lblsql.grid(row = i, column = 1)
i = 0
c.execute('SELECT descrizione FROM contabilita')
for row2 in c.fetchall():
i += 1
lblsql = Label(root, text=row2, width=30, bg = 'white', padx=5, pady=5)
lblsql.grid(row = i, column = 2)
c.execute('SELECT movimento FROM contabilita')
i = 0
for row3 in c.fetchall():
i += 1
lblsql = Label(root, text=row3, width=15, bg = 'white', padx=5, pady=5)
lblsql.grid(row = i, column = 3)
conn = sqlite3.connect('contabilita.db')
c = conn.cursor()
root = Tk()
root.title('Contabilità')
root.geometry('1008x630+200+200')
lbl1 = Label(root, text='Data', width=15)
lbl2 = Label(root, text='Descrizione', width=30)
lbl3 = Label(root, text='Movimento', width=15)
bt1 = Button(root, text='inserisci', width=10, command=inserimento_dati)
bt4 = Button(root, text='grafico', width=10, command=plot)
bt5 = Button(root, text='esci', width=10, command=esci)
lbl1.grid(row=0, column=1)
lbl2.grid(row=0, column=2)
lbl3.grid(row=0, column=3)
bt1.grid(row=1, column=0)
bt4.grid(row=2, column=0)
bt5.grid(row=3, column=0)
visualizza()
root.mainloop()