python从接口将数据插入sqlite 3
所以我用Python3设计了一个基于终端的应用程序,我发现为这个应用程序设计了GUI。我在sqlite3中设计了一个数据库,现在我的问题是,当我点击提交按钮时,我必须从GUI中插入数据到数据库中。基本上我有前端和后端,剩下的是连接python从接口将数据插入sqlite 3,python,tkinter,Python,Tkinter,所以我用Python3设计了一个基于终端的应用程序,我发现为这个应用程序设计了GUI。我在sqlite3中设计了一个数据库,现在我的问题是,当我点击提交按钮时,我必须从GUI中插入数据到数据库中。基本上我有前端和后端,剩下的是连接 # import Statements # Used Api Library "ttt" from tkinter import * from tkinter import ttk from tkinter import messagebox # class is
# import Statements
# Used Api Library "ttt"
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
# class is made
class MovieOrganizer:
#init method
def __init__(self, master):
# <----- Header Coding starts here ------->
self.frame_header = ttk.Frame(master)
self.frame_header.pack()
#Importing the picture
self.logo = PhotoImage(file = 'movie_logo.png')
# creating the labels in the frame header.
ttk.Label(self.frame_header, image = self.logo).grid(row = 0, column = 0, rowspan = 2)
ttk.Label(self.frame_header, text = 'Welcome to movie organizer!').grid(row = 0, column = 1)
ttk.Label(self.frame_header, wraplength = 300,
text = ("By the application you easily know different category of movies you want to watch and when to watch. "
"You can also categorize the movies, save the date you watched and find the location of the movie in your systm.")).grid(row = 1, column = 1)
# <----- Content Coding starts here ------->
self.frame_content = ttk.Frame(master)
self.frame_content.pack()
# creating the labels in the frame content.
ttk.Label(self.frame_content, text = 'Movie Name:').grid(row = 0, column = 0, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Movie category:').grid(row = 0, column = 1, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Date you watched:').grid(row = 2, column = 0, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Rate the movie out of 10:').grid(row = 2, column = 1, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Any Comments on the movie?:').grid(row = 4, column = 0, padx = 5, sticky = 'sw')
# I need to add more label later on.
#input fields for the label created
#varible is assigned
self.entry_name = ttk.Entry(self.frame_content, width = 24)
self.entry_category = ttk.Entry(self.frame_content, width = 24)
self.entry_category = ttk.Entry(self.frame_content, width = 24)
self.entry_date = ttk.Entry(self.frame_content, width = 24)
self.entry_rate = ttk.Entry(self.frame_content, width = 24)
#self.check()
self.text_comments = Text(self.frame_content, width = 50, height = 10)
#position setting for the inputs
self.entry_name.grid(row = 1, column = 0, padx = 5)
self.entry_category.grid(row = 1, column = 1, padx = 5)
self.entry_date.grid(row = 3, column = 0, padx = 5)
self.entry_rate.grid(row = 3, column = 1, padx = 5)
self.text_comments.grid(row = 5, column = 0, columnspan = 2, padx = 5)
#setting the buttons submit button submit form to db and clear clears all the values for a reentery
# I need to add 2 more button but db connectivity should be there. One button is a view button I will put a view for all the movies. And second button is delete the entry
ttk.Button(self.frame_content, text = 'Submit', command = self.submit).grid(row = 6, column = 0, padx = 5, pady = 5, sticky = 'e')
ttk.Button(self.frame_content, text = 'Clear', command = self.clear).grid(row = 6, column = 1, padx = 5, pady = 5, sticky = 'w')
#ttk.Button(self.frame_content, text = '', command = self.view).grid(row = 6, column = 2, padx = 5, pady = 5, sticky = 'e')
# an if coditon Want to fix it before next prototype.
# def check(self):
# if self.entry_rate <10:
# messagebox.showinfo(title = 'New Movie Entry ', message = 'Updated!')
# this method works on submit button
def submit(self):
print('Name: {}'.format(self.entry_name.get()))
print('Category: {}'.format(self.entry_category.get()))
print('Date: {}'.format(self.entry_date.get()))
print('Rate: {}'.format(self.entry_rate.get()))
print('Comments: {}'.format(self.text_comments.get(1.0, 'end')))
self.clear()
messagebox.showinfo(title = 'New Movie Entry ', message = 'Updated!')
def clear(self):
self.entry_name.delete(0, 'end')
self.entry_category.delete(0, 'end')
self.entry_date.delete(0, 'end')
self.entry_rate.delete(0, 'end')
self.text_comments.delete(1.0, 'end')
# def view(self):
def main():
root = Tk()
movieOrganizer = MovieOrganizer(root)
root.mainloop()
#if conditiom
if __name__ == "__main__": main()
我是一个新手,但是看看你的代码,你在同一页的代码片段中没有得到任何sqlite的连接,如果你得到了它,你可以修复损坏的代码并将每一行附加到它,所以在最后你得到了db和运行的代码 很抱歉为我的数据库添加了代码>>>con sqlite3.connect'hrdb'语法错误:无效语法>>>con=sqlite3.connect'hrdb'>>>键入con>>cur=con.cursor>>>cur.execute'CREATE TABLE moview id integer primary key,Movie varchar50,category vatchar50,date varchar50,rate integer,评论varchar50'你的问题是什么?您遇到的问题是什么?我需要在单击“提交”按钮时从界面输入数据。我已经制作了接口和数据库,但是我不能将接口中的数据输入数据库,这意味着什么?你有错误吗?如果是这样的话,有什么错误?我想指出的是,这篇文章已经停刊近两年了,对上面的评论没有任何回应。祝你好运得到回复,欢迎来到StackOverflow!