此内容来自第三方平台 (Dailymotion)。如果此视频侵犯了您的版权,请使用 立即删除 工具。
Basic Database Insert with Python Tkinter
描述
A very basic programming tutorial in Python Tkinter database. I know I refer to another video, but you are really not missing much. It's a very similar video where all of the entry fields and buttons are on one screen, and this one has them separated out a little more.
Code:
#imports
from Tkinter import *
import sqlite3
#root setup
root = Tk()
root.title("Tkinter Sqlite 2nd")
root.minsize(width = 300, height = 300)
root.maxsize(width = 300, height = 300)
#create the database
db = sqlite3.connect('mydb100.db')
cursor = db.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS people(id INTEGER PRIMARY KEY, name TEXT, phone TEXT)")
db.commit()
db.close()
#the basic elements for the root window
list = Listbox(root) #the listbox that will get updated
name = StringVar()
phone = StringVar()
#the insert function
def insert():
name_i = name.get()
phone_i = phone.get()
conn = sqlite3.connect('mydb100.db')
with conn:
cursor = conn.cursor()
cursor.execute('INSERT INTO people(name, phone) VALUES(?,?)',(name_i, phone_i,))
lis = cursor.execute('SELECT name, phone FROM people')
for item in lis:
list.insert(END, item)
db.close()
#the insert window
def insert_window():
inwin = Toplevel()
inwin.title("Insert")
ne = Entry(inwin, textvariable = name)
pe = Entry(inwin, textvariable = phone)
button = Button(inwin, text = "Insert", command = insert)
ne.pack()
pe.pack()
button.pack()
#load the stuff
connt = sqlite3.connect('mydb100.db')
with connt:
cur = connt.cursor()
lit = cur.execute('SELECT name, phone FROM people')
for item in lit:
list.insert(0, item)
db.close()
#the insert button
ibutton = Button(root, text = "Launch Insert Window", command = insert_window)
#the main window
ibutton.pack()
list.pack()
root.mainloop()
Code:
#imports
from Tkinter import *
import sqlite3
#root setup
root = Tk()
root.title("Tkinter Sqlite 2nd")
root.minsize(width = 300, height = 300)
root.maxsize(width = 300, height = 300)
#create the database
db = sqlite3.connect('mydb100.db')
cursor = db.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS people(id INTEGER PRIMARY KEY, name TEXT, phone TEXT)")
db.commit()
db.close()
#the basic elements for the root window
list = Listbox(root) #the listbox that will get updated
name = StringVar()
phone = StringVar()
#the insert function
def insert():
name_i = name.get()
phone_i = phone.get()
conn = sqlite3.connect('mydb100.db')
with conn:
cursor = conn.cursor()
cursor.execute('INSERT INTO people(name, phone) VALUES(?,?)',(name_i, phone_i,))
lis = cursor.execute('SELECT name, phone FROM people')
for item in lis:
list.insert(END, item)
db.close()
#the insert window
def insert_window():
inwin = Toplevel()
inwin.title("Insert")
ne = Entry(inwin, textvariable = name)
pe = Entry(inwin, textvariable = phone)
button = Button(inwin, text = "Insert", command = insert)
ne.pack()
pe.pack()
button.pack()
#load the stuff
connt = sqlite3.connect('mydb100.db')
with connt:
cur = connt.cursor()
lit = cur.execute('SELECT name, phone FROM people')
for item in lit:
list.insert(0, item)
db.close()
#the insert button
ibutton = Button(root, text = "Launch Insert Window", command = insert_window)
#the main window
ibutton.pack()
list.pack()
root.mainloop()
相关视频
Android Application Development - 117 - Inserting Data into SQLite Database
Bollywoodaction
Python Tkinter GUI Tutorial 2 - How to Create Calculator
Sung Chilton
FULL PROJECT: SQLITE dan PYQT (Python GUI) Untuk Pemula: PART 1
Balige Academy
Java Eclipse GUI Tutorial 4 # Database Connection ( Sqlite ) to Java Part 2 of 2 - oyestontech.com
Oyestontech
Java Eclipse GUI Tutorial 3 # Database Connection ( Sqlite ) to Java Part 1 of 2 - oyestontech.com
Oyestontech
Build GUI Application with Python and Tkinter
SERIES