【发布时间】:2018-02-19 06:01:40
【问题描述】:
我一直在阅读使用 get() 是执行此操作的最佳方法,但我不确定如何使用它,其他答案对我没有帮助。 以下是代码的主要部分。我正在使用 python 3.6、tkinter 和 sqlite3。
import sqlite3
import tkinter as tk
from tkinter import Frame, Tk, Button, Label, Entry, N, S, E, W
from tkinter import TOP, BOTTOM, LEFT, RIGHT, END, ALL
top=Tk()
top.geometry("320x225")
top.title('dvd rentals')
medium_font=('Veranda', 10)
textFrame=Frame(top)
loaneeID=Label()
loaneeID=Label(top,font=medium_font,text='Loanee ID ')
loaneeID.grid(row=2, column=1)
entry1=Entry(textFrame)
entry1=Entry(top, bd = 5, font=medium_font, width=25)
entry1.grid(row=2, column=2)
submit_button = tk.Button(top, text='Add Item', width=8,
command=lambda: add_item(top))
submit_button.grid(row=8, column=1, sticky=E, pady=20, padx=20)
top.mainloop()
def main():
conn = sqlite3.connect('dvd.db')
c=conn.cursor()
def tableCreate(c):
c.execute('CREATE TABLE IF NOT EXISTS loanee (loaneeID int, name text, email text)')
c.execute('CREATE TABLE IF NOT EXISTS dvd (dvdID int, name text)')
c.execute('CREATE TABLE IF NOT EXISTS loan (loaneeID int, dvdID int, start date text, end date text)')
def insertValues(c, loanee, dvd, loan):
c.execute('INSERT INTO loanee VALUES (?,?,?)',loanee)
c.execute('INSERT INTO dvd VALUES (?,?)',dvd)
c.execute('INSERT INTO loan VALUES (?,?,?,?)',loan)
tableCreate(c)
insertValues(c, loanee, dvd, loan)
conn.commit()
conn.close()
main()
我的目标是用户输入他们的 ID(和其他条目),他们可以使用指定的提交按钮将其添加到数据库中。
【问题讨论】:
标签: python python-3.x tkinter sqlite