我正在尝试将此表作为桌面应用程序(而不是web)来执行。它应该是一个可编辑的表,允许用户引入自己的数据(输入),将其保存在数据库中(使用sqlite连接到数据库),如果数据库中已经有一些信息,则将其显示到表中,并且不允许用户更改。这使一个表像我想要的,但我不知道如何使用它的网格,因为它需要所有屏幕,我希望它下面的选择列表选项。非常感谢!我会让我的代码在下面。
from tkinter import ttk
from tkinter import *
from tkcalendar import Calendar, DateEntry
import sqlite3
class Client:
dbName = 'Database.db'
def __init__(self, window):
self.wind = window
self.wind.title('Aplicación cliente')
#Container
frame = LabelFrame(self.wind, text = 'Registrar un nuevo cliente')
frame.grid(row=0, column=0, columnspan=1, padx=20, pady=20)
#Name input
Label(frame, text = 'Nombre: ').grid(row=1, column=0)
self.name = Entry(frame)
self.name.focus
self.name.grid(row=1, column=1, padx=10, pady=5)
#Birth date input
Label(frame, text = 'Fecha de nacimiento: ').grid(row=2, column=0)
self.calendar = DateEntry(frame,width=30,bg="darkblue",fg="white")
self.calendar.grid(row=2, column=1, padx=10, pady=5)
Label(frame, text = 'Fecha de bautismo: ').grid(row=3, column=0)
self.calendar = DateEntry(frame,width=30,bg="darkblue",fg="white")
self.calendar.grid(row=3, column=1, padx=10, pady=5)
#Select list
var = StringVar()
Label(frame, text = 'Grupo: ').grid(row=4, column=0)
self.dropdownList = OptionMenu(frame, var, 'Hombre', 'Mujer', 'Anciano', 'Siervo ministerial', 'Precursor regular', 'Ungido', 'Otras ovejas')
self.dropdownList.grid(row=4, column=1, padx=10, pady=5)
rows = []
for i in range(12):
cols = []
for j in range(7):
e = Entry(relief=RIDGE)
e.grid(row=i, column=j, sticky=NSEW)
e.insert(END, '%d.%d' % (i, j))
cols.append(e)
rows.append(cols)
def onPress():
for row in rows:
for col in row:
print(col.get())
print
Button(text='Fetch', command=onPress).grid()
def run_query(self, query, parameters=()):
with sqlite3.connect(self.dbName) as conn:
cursor = conn.cursor()
result = cursor.execute(query, parameters)
conn.commit()
return result
def getClient(self):
records = self.tree.get_children()
for element in records:
self.tree.delete(element)
query = 'SELECT * FROM Client'
dbRows = self.run_query(query)
for row in dbRows:
self.tree.insert('',0, text=row[1], values=row[2])
if __name__ == '__main__':
window = Tk()
application = Client(window)
window.mainloop()
1条答案
按热度按时间thtygnil1#
只是为了展示我的成就。让我知道您缺少什么,因为我不使用sqlite和tkcalendar。