Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 通过用户输入tkinter编辑当前表格值_Python 3.x_Sqlite_Tkinter - Fatal编程技术网

Python 3.x 通过用户输入tkinter编辑当前表格值

Python 3.x 通过用户输入tkinter编辑当前表格值,python-3.x,sqlite,tkinter,Python 3.x,Sqlite,Tkinter,我不确定这个问题是否真的得到了回答,因为我发现了类似的问题,并尝试了解决方案,但没有得到预期的结果 我要运行以下脚本来更新现有表中的数据: from tkinter import * import sqlite3 from tkinter.ttk import * import sys from datetime import datetime root = Tk() root.geometry('380x250') root.title("Stock Movement")

我不确定这个问题是否真的得到了回答,因为我发现了类似的问题,并尝试了解决方案,但没有得到预期的结果

我要运行以下脚本来更新现有表中的数据:

from tkinter import *
import sqlite3
from tkinter.ttk import *
import sys
from datetime import datetime

root = Tk()
root.geometry('380x250')
root.title("Stock Movement")
root.config(bg="lightskyblue1")
style = Style()

ItemCode = StringVar()
Description = StringVar()
Quantity = IntVar()
var = IntVar()
c = StringVar()
var1 = IntVar()
var2 = IntVar()
dateTimeObj = datetime.now()

timestampStr = dateTimeObj.strftime("%d-%b-%Y")


def database():
    code = ItemCode.get()
    quantity = Quantity.get()
    description = Description.get()

    with sqlite3.connect('Test.sql3') as conn:
        cursor = conn.cursor()


        # I believe I would need to edit the next line to add a variable, but that messes around with the amount of variables used. I have to try and only add or subtract an integer where a certain Itemcode is found. 
        cursor.execute('UPDATE StockSheet SET Quantity=?, LastRec=? WHERE ItemCode=?', (quantity, timestampStr, code,))


        updated = cursor.rowcount
        cursor.close()
        conn.commit()
        root.destroy()
        sys.exit(updated)  # return value whether record has been updated

# Inserting labels and field of input
label_0 = Label(root, text="Stock Movement", background="lightskyblue1", width=20, font=("Arial", 20, "bold")).place(x=90, y=23)

label_1 = Label(root, text="Item Code", width=20, background="lightskyblue1", font=("Arial", 12, "bold")).place(x=20, y=100)

entry_1 = Entry(root, textvar=ItemCode, background="lightskyblue1", font=("Arial", 12, "bold")).place(x=180, y=100)

label_2 = Label(root, text="Quantity", width=10, background="lightskyblue1", font=("Arial", 12, "bold")).place(x=20, y=140)

entry_2 = Entry(root, textvar=Quantity, background="lightskyblue1", font=("Arial", 12, "bold")).place(x=180, y=140)


# Style of buttons
style.configure('C.TButton', font=('Arial', 12, 'bold'), foreground='red')
style.configure('S.TButton', font=('Arial', 12, 'bold'), foreground='blue')

# Inserting buttons
submit1 = Button(root, text='Submit', style='S.TButton', width=11, command=database).place(x=20, y=190)
exit1 = Button(root, text='Close', style='C.TButton', width=11, command=root.destroy).place(x=260, y=190)

root.mainloop()
目前它正在替换当前值,例如,当前数据库中的数量为250。用户输入100。数据库显示100。 我想知道对我来说,加上或减去这个值是否可以得到一个分别显示350/150的结果

我已经阅读了SQL文档,但从这个意义上讲,它似乎相当模糊

我以前曾尝试将SQL数据用作
IntVar
,并在代码中使用它,但没有成功


任何帮助都将不胜感激。

您是否尝试过SQL语句中的
Quantity=Quantity+?
。@acw1668工作正常。有时我会迷失在python和SQL之间的协作语法中。我假设如果需要做减法,你可以输入一个负数。同样有效。非常感谢你。看起来我必须感谢您对我的最终程序的帮助。@acw1668如果它运行脚本,但不更改数据库中的值,可能会有什么问题?没有错误,只是没有更改。请尝试交换
游标。关闭()
连接。提交()
@acw1668工作正常!!非常感谢。有时我会感到困惑,因为
cursor.close()
conn.commit()之前在逻辑上是有意义的。