私はこれを行うための最良の方法はget()を使用して読んできましたが、私はそれを使用する方法がわかりません、そして、他の答えは私に役立っていません。 以下はコードの主要部分です。私は、Python 3.6、tkinterとsqlite3を使用しています。入力ウィジェットから入力を受け取り、それを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(およびその他のエントリ)をユーザーが入力することです。
これは、ボタンの前に追加する必要がありますが、残りのtkinterのものを追加する必要があります。 – CyberSkull311
また、上記のコードを使用すると、loanee_idが定義されていないというエラーが発生します。 – CyberSkull311