Python 问题-Tkinter需要检查输入框中的值是否已经在我的sqlite数据库表中的特定列中
我是这个社区的新手,我正在尝试学习python,我的版本是3.7,适用于windows 10 我已经创建了这个程序,我将用python/Tkinter附加下面的代码 这就是我被困的地方: 当用户按下Submit按钮时,我需要检查输入框分配号(如果您启动该程序,它位于GUI顶部)是否已经存在于我的sqlite3表中,然后再插入用户提交的所有数据,这些数据将存储在数据库中 基本上,我需要每个调查提交有一个唯一的任务编号 如果你能帮忙,那就太好了一个星期没睡觉了 提前感谢你的帮助Python 问题-Tkinter需要检查输入框中的值是否已经在我的sqlite数据库表中的特定列中,python,sqlite,tkinter,Python,Sqlite,Tkinter,我是这个社区的新手,我正在尝试学习python,我的版本是3.7,适用于windows 10 我已经创建了这个程序,我将用python/Tkinter附加下面的代码 这就是我被困的地方: 当用户按下Submit按钮时,我需要检查输入框分配号(如果您启动该程序,它位于GUI顶部)是否已经存在于我的sqlite3表中,然后再插入用户提交的所有数据,这些数据将存储在数据库中 基本上,我需要每个调查提交有一个唯一的任务编号 如果你能帮忙,那就太好了一个星期没睡觉了 提前感谢你的帮助 import bac
import backend
import csv
from backend import write_to_csv
import os
from Send_email_gui import send_email
from backend import check_assignment
def add_entry_command():
#check_assignment_no.check_assignment(assignment_no_text.get())
if check_assignment(assignment_no_text.get())== 0:
backend.insert(client_code_text.get(), client_name_text.get(), assignment_no_text.get(), accountant_text.get(), year_end_text.get(), file_presentation_text.get(), quality_of_job_processed_text.get(), queries_text.get(), indexing_text.get(), final_reports_text.get(), documents_handling_text.get(), meeting_deadlines_text.get(), communication_text.get(), analytical_review_text.get(), overall_job_text.get(), suggestion_text.get())
send_email(accountant_text, client_code_text, client_name_text, assignment_no_text, year_end_text, file_presentation_text, quality_of_job_processed_text, queries_text, indexing_text, final_reports_text, documents_handling_text, meeting_deadlines_text, communication_text, analytical_review_text, overall_job_text, suggestion_text)
messagebox.showinfo('Confirmation', 'Thank you for your submission, click ok and close')
else:
messagebox.showinfo('Assignment number used', 'Assignment number already used, please check again and submit')
def __init__(self, assignment_no_, accountant_, year_end_, client_code_, client_name_, file_presentation_, quality_of_job_processed_, queries_,
indexing_, final_reports_, documents_handling_, meeting_deadlines_, communication_, analytical_review_, overall_rate_, suggestion_):
self.assignment_no_=assignment_no_
self.accountant_=accountant_
self.year_end_=year_end_
sel.client_code_=client_code_
self.client_name_=client_name_
self.file_presentation_=file_presentation_
self.quality_job_=quality_of_job_processed_
self.queries_assumptions_=queries_
self.indexing_cross_ref_=indexing_
self.final_reports_=final_reports_
self.doc_handling_=documents_handling_
self.meet_deadlines_=meeting_deadlines_
self.communi_=communication_
self.analytical_rev_=analytical_review_
self.overall_rate_=overall_rate_
self.suggestion_box_=suggestion_
window=Tk()
"""
Center the window of the program
"""
# Gets the requested values of the height and widht.
windowWidth = window.winfo_reqwidth()
windowHeight = window.winfo_reqheight()
#print("Width",windowWidth,"Height",windowHeight)
# Gets both half the screen width/height and window width/height
positionRight = int(window.winfo_screenwidth()/6 - windowWidth/6)
positionDown = int(window.winfo_screenheight()/6 - windowHeight/6)
# Positions the window in the center of the page.
window.geometry("+{}+{}".format(positionRight, positionDown))
"""
Top data entry level
TO DO - build function to return client name directly from Iris database - build button
"""
label_title=Label(window, text="Global Infosys feedback collector", height=3, fg="blue", font=(20))
label_title.grid(row=0, column=2)
l1=Label(window, text="Client code")
l1.grid(row=4, column=1, sticky='E')
l2=Label(window, text="Client name")
l2.grid(row=4, column=3, sticky='E')
l3=Label(window, text="Assignment no:")
l3.grid(row=5, column=1, sticky='E')
l4=Label(window, text="Accountant:")
l4.grid(row=6, column=1, sticky='E')
l5=Label(window, text="Year end:")
l5.grid(row=7, column=1, sticky='E')
"""
Second and third titles - form beginning
"""
label_second_title=Label(window, text="Scoring Referance (enter only 1 number):", height=3, fg="blue")
label_second_title.grid(row=8, column=1, columnspan=2, sticky=W)
label_third_title=Label(window, text="Excellent: 10 | Good: 9 - 8 | Avarage: 7 - 6 | Poor: 0 - 5", height=3, fg="blue")
label_third_title.grid(row=9, column=1, columnspan=2, sticky=W)
empty_label=Label(window, text=" ", width=15)
empty_label.grid(row=9, column=0)
second_empty_label=Label(window, text=" ", width=15)
second_empty_label.grid(row=4, column=6)
#third_empty_label=Label(window, text="View Entry", height=3)
#third_empty_label.grid(row=26, column=1)
"""
Form level labels
"""
l6=Label(window, text="File presentation:")
l6.grid(row=10, column=1, sticky='E')
l7=Label(window, text="Quality of job processing")
l7.grid(row=11, column=1, sticky='E')
l8=Label(window, text="Queries and assumptions:")
l8.grid(row=12, column=1, sticky='E')
l9=Label(window, text="Indexing and cross referencing:")
l9.grid(row=13, column=1, sticky='E')
l10=Label(window, text="Final reports (draft accounts):")
l10.grid(row=14, column=1, sticky='E')
l11=Label(window, text="Documents handling / usage:")
l11.grid(row=15, column=1)
l12=Label(window, text="Meeting deadlines:")
l12.grid(row=16, column=1, sticky='E')
l13=Label(window, text="Communication:")
l13.grid(row=17, column=1, sticky='E')
l14=Label(window, text="Analytical review:")
l14.grid(row=18, column=1, sticky='E')
l15=Label(window, text="Overall Job rating:")
l15.grid(row=19, column=1, sticky='E')
l16=Label(window, text="Suggestion / Review:")
l16.grid(row=20, column=1, sticky='E')
l25=Label(window, text="@ A production of Shehan H.", fg="red")
l25.grid(row=30, column=6, sticky='E')
"""
Entry boxes top
"""
client_code_text=StringVar()
e1=Entry(window, textvariable=client_code_text)
e1.grid(row=4, column=2)
client_name_text=StringVar()
e2=Entry(window, textvariable=client_name_text)
e2.grid(row=4, column=4)
assignment_no_text=StringVar()
e3=Entry(window, textvariable=assignment_no_text)
e3.grid(row=5, column=2)
accountant_text=StringVar()
e4=Entry(window, textvariable=accountant_text)
e4.grid(row=6, column=2)
year_end_text=StringVar()
e5=Entry(window, textvariable=year_end_text)
e5.grid(row=7, column=2)
"""
Entry boxes form level
"""
file_presentation_text=StringVar()
e6=Entry(window, textvariable=file_presentation_text)
e6.grid(row=10, column=2)
quality_of_job_processed_text=StringVar()
e7=Entry(window, textvariable=quality_of_job_processed_text)
e7.grid(row=11, column=2)
queries_text=StringVar()
e8=Entry(window, textvariable=queries_text)
e8.grid(row=12, column=2)
indexing_text=StringVar()
e9=Entry(window, textvariable=indexing_text)
e9.grid(row=13, column=2)
final_reports_text=StringVar()
e10=Entry(window, textvariable=final_reports_text)
e10.grid(row=14, column=2)
documents_handling_text=StringVar()
e11=Entry(window, textvariable=documents_handling_text)
e11.grid(row=15, column=2)
meeting_deadlines_text=StringVar()
e12=Entry(window, textvariable=meeting_deadlines_text)
e12.grid(row=16, column=2)
communication_text=StringVar()
e13=Entry(window, textvariable=communication_text)
e13.grid(row=17, column=2)
analytical_review_text=StringVar()
e14=Entry(window, textvariable=analytical_review_text)
e14.grid(row=18, column=2)
overall_job_text=StringVar()
e15=Entry(window, textvariable=overall_job_text)
e15.grid(row=19, column=2)
suggestion_text=StringVar()
e16=Entry(window, textvariable=suggestion_text, width=50)
e16.grid(row=20, column=2, padx=5,pady=10,ipady=3)
"""
Buttons
"""
b1=Button(window, text="Submit to GI", width=12, command=add_entry_command)
b1.grid(row=25, column=2)
b2=Button(window, text="Export report", width=12, command=write_to_csv)
b2.grid(row=25, column=3)
b3=Button(window, text="Connect client", width=12)
b3.grid(row=4, column=5)
"""
List box to view results
Maight be deleted and changed with popup to confirm
list1=Listbox(window, height=1, width=70)
list1.grid(row=26, column=2)
"""
window.mainloop()
这是后端模块
import sqlite3
import csv
import os
from tkinter import messagebox
from tkinter import *
def connect():
conn=sqlite3.connect("lite.db")
cur=conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS gi_store (id INTEGER PRIMARY KEY, client_code_ text, client_name_ text, assignment_no_ text, accountant_ text, year_end_ text, file_presentation_ integer, quality_of_job_processed_ integer, queries_ integer, indexing_ integer, final_reports_ integer, documents_handling_ integer, meeting_deadlines_ integer, communication_ integer, analytical_review_ integer, overall_job_ integer, suggestion_ text)")
conn.commit()
conn.close()
def insert(client_code_, client_name_, assignment_no_, accountant_, year_end_, file_presentation_, quality_of_job_processed_, queries_, indexing_, final_reports_, documents_handling_, meeting_deadlines_, communication_, analytical_review_, overall_job_, suggestion_):
conn=sqlite3.connect("lite.db")
cur=conn.cursor()
cur.execute("INSERT INTO gi_store VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (client_code_, client_name_, assignment_no_, accountant_, year_end_, file_presentation_, quality_of_job_processed_, queries_, indexing_, final_reports_, documents_handling_, meeting_deadlines_, communication_, analytical_review_, overall_job_, suggestion_))
conn.commit()
conn.close()
def view():
conn=sqlite3.connect("lite.db")
cur=conn.cursor()
cur.execute("SELECT * FROM gi_store")
rows=cur.fetchall()
conn.close()
return rows
def write_to_csv():
conn=sqlite3.connect("lite.db")
cur=conn.cursor()
cur.execute("SELECT * FROM gi_store")
csvWriter = csv.writer(open("output.csv", "w", newline=''))
rows = cur.fetchall()
csvWriter.writerow(["ID", "Client Code", "Client Name", "Assignment number", "Accountant", "Year End", "File Presentation", "Quality of job processed", "Queries", "Indexing", "Final reports", "Doc. handling", "Meeting deadlines", "Communication", "Analytical review", "Overall rate", "Suggestion box"])
for row in rows:
# do your stuff
csvWriter.writerow(row)
conn.close()
def check_assignment(assignment_no_):
conn=sqlite3.connect("lite.db")
cur=conn.cursor()
control_assignment = cur.execute("SELECT * FROM gi_store WHERE assignment_no_ = ?", (assignment_no_,))
control_assignment_row=cur.fetchone()
conn.close()
return control_assignment_row
connect()
#print(check_assignment(assignment_no_text="2"))
您的函数检查\u赋值返回的行的赋值号为或为零,但与0比较。你应该与无相比较
id应该是唯一的,所以可能使用id而不是作业编号Hi furas,谢谢您的评论,问题是另一家公司会给我们作业编号,我们不想在这份调查表中填写代码。这个gui程序将被其他20个人使用,我想避免他们错误地输入相同的分配号代码。谢谢,我看到你用check_作业来检查它-它不工作吗?你有错误吗?始终将完整的错误消息从有问题的单词回溯开始,而不是作为文本而不是屏幕截图进行注释。还有其他有用的信息。请使用“打印”查看您从check_分配中获得的信息-它可能是单行或无,但您可以将其与0进行比较-您更希望check不是无。或者您应该使用SELECT COUNT*从数据库中获取数字。非常感谢Furas!成功了!你真的帮了大忙,再次谢谢你,祝你周末愉快
if check_assignment(assignment_no_text.get()) is None: