[英]how can create multiple tables in database by using tkinter
嘿伙計們,我有一個問題,我有一個應用程序的想法,但它需要在數據庫中創建多個表,並且用戶使用“tkinter”條目指定其名稱
我使用過這個查詢,但它不起作用
cr.execute("""create table {}(text1 text,text2 text ,var1 float,var2 float
""".format(table_name))
在此處添加示例代碼以供參考。 請按照@Alias 的建議通讀。
from tkinter import *
import sqlite3
def create_conn(dbf):
conn = None
try:
conn = sqlite3.connect(dbf)
except Error as e:
print(e)
return conn
def create_table(conn, tname):
cur = conn.cursor()
sqlstrng = "create table "+ tname + "(id integer)"
cur.execute(sqlstrng)
def start(tname):
dbfile = r"C:\sqllite\sqlite-tools-win32-x86-3380300\testdb.db"
# Create DB connection
conn = create_conn(dbfile)
create_table(conn,tname)
ws = Tk()
ws.title('get text demo')
ws.geometry('210x210')
def startTabCreation():
tname = name_Tf.get()
start(tname)
Label(ws, text="Enter Name").pack()
name_Tf = Entry(ws)
name_Tf.pack()
Button(ws, text="Create Table", command=startTabCreation).pack()
ws.mainloop()
請參閱此處的代碼運行演示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.