鱼C论坛

 找回密码
 立即注册
查看: 3146|回复: 6

信息添加修改报错

[复制链接]
发表于 2021-6-30 21:30:32 | 显示全部楼层 |阅读模式
10鱼币
  1. import sys
  2. import tkinter.messagebox
  3. from tkinter import *
  4. import tkinter.tix
  5. import sqlite3
  6. root=tkinter.tix.Tk()
  7. root.title("人工智能学院学生奖学金信息编辑")
  8. winWidth=700
  9. winHeight=280
  10. zzy=StringVar()
  11. zxm=StringVar()
  12. zxh=StringVar()
  13. zxq=StringVar()
  14. zjxjdj=StringVar()

  15. #获取屏幕分辨率
  16. screenWidth=root.winfo_screenwidth()
  17. screenHeight=root.winfo_screenheight()
  18. #设置窗口初始位置在屏幕居中
  19. x=int((screenWidth-winWidth)/2)
  20. y=int((screenHeight-winHeight)/2)
  21. root.geometry("%sx%s+%s+%s"%(winWidth,winHeight,x,y))

  22. def turn_save(event):
  23.     try:
  24.         conn=sqlite3.connect('人工院信息.db')
  25.     except:
  26.         print("提示","打开人工院信息.db库连接出错,请检查!")
  27.         conn.close()
  28.         sys.exit()
  29.     cur=conn.cursor()
  30.     curTable="学生奖学金信息"
  31.     selectSQL="insert into 学生奖学金信息 values('"+zzy.get()+"','"+zxm.get()+"','"+zxh.get()+"','"+zxq.get()+"','"+zjxjdj.get()+"')"
  32.    
  33.     cur.execute(selectSQL)
  34.     conn.commit()
  35.     tree.insert("",0,text="",values=(zzy.get(),zxm.get(),zxh.get(),zxq.get(),zjxjdj.get()))
  36.     cur.close()
  37.     conn.close()
  38.     tkinter.messagebox.showinfo('提示','记录保存成功!')

  39. #更新表中数据
  40. def table_update(event):
  41.     conn=sqlite3.connect('人工院信息.db')
  42.     cur=conn.cursor()
  43.     updateSQL="update 学生奖学金信息 set zy='"+zzy.get()+"',xm='"+zxm.get()+"',xh='"+zxh.get()+"',xq='"+zxq.get()+"',jxjdj='"+zjxjdj.get()+"' where xh='"+zxh.get()+"'"
  44.     cur.execute(updateSQL)
  45.     conn.commit()
  46.     getSQLDate()

  47. def turn_property(even):
  48.     getSQLDate()
  49. def getSQLDate():
  50.     try:
  51.         conn=sqlite3.connect('人工院信息.db')
  52.     except:
  53.         print("提示","打开人工院信息.db库连接出错,请检查!")
  54.         conn.close()
  55.         sys.exit()

  56.     x=tree.get_children()
  57.     for item in x:
  58.         tree.delete(item)

  59.     cur=conn.cursor()
  60.     curTable="学生奖学金信息"
  61.     cur.execute("select * from 学生奖学金信息")
  62.     for row in cur.fetchall():
  63.         tree.insert("",0,text="",values=(row[0],row[1],row[2],row[3],row[4]))
  64.     cur.close()
  65.     conn.close()

  66. #删除表中数据
  67. def table_delete(event):
  68.     conn=sqlite3.connect('人工院信息.db')
  69.     cur=conn.cursor()
  70.     cur.execute("delete from 学生奖学金信息 where xh='"+zxh.get()+"'")
  71.     conn.commit()
  72.     getSQLDate()
  73.    
  74. def clearInput():
  75.     zzy=""
  76.     zxm=""
  77.     zxh=""
  78.     zxq=""
  79.     zjxjdj=""   

  80. #单击某条记录显示至输入框
  81. form_record=[]
  82. def record_show_to_input():
  83.     global form_record
  84.     clearInput()
  85.     zzy.set(form_record[0])
  86.     zxm.set(form_record[1])
  87.     zxh.set(form_record[2])
  88.     zxq.set(form_record[3])
  89.     zjxjdj.set(form_record[4])

  90. #表格点击响应函数
  91. def selectTree(event):
  92.     global form_record
  93.     form_record=tree.item(tree.selection(),"values")
  94. #显示至输入框
  95.     record_show_to_input()

  96. import tkinter as tk
  97. from tkinter.constants import *
  98. from tkinter import ttk
  99. tree=ttk.Treeview(root)
  100. tree["columns"]=("zy","xm","xh","xq","jxjdj")
  101. tree.column("zy",width=100)
  102. tree.column("xm",width=100)
  103. tree.column("xh",width=100)
  104. tree.column("xq",width=100)
  105. tree.column("jxjdj",width=100)

  106. tree.heading("zy",text="专业")
  107. tree.heading("xm",text="姓名")
  108. tree.heading("xh",text="学号")
  109. tree.heading("xq",text="学期")
  110. tree.heading("jxjdj",text="奖学金等级")

  111. tree.pack(side="top")
  112. top=tkinter.tix.Frame(root,relief=RAISED,bd=1)
  113. top.pack(side="left")
  114. top.zy1=tkinter.tix.LabelEntry(top,label="      专业:",labelside='top',)
  115. top.zy1.pack(side="left")
  116. top.zy1.entry['textvariable']=zzy
  117. top.xm1=tkinter.tix.LabelEntry(top,label="  姓名:",labelside='top',)
  118. top.xm1.pack(side="left")
  119. top.xm1.entry['textvariable']=zxm
  120. top.xh1=tkinter.tix.LabelEntry(top,label="            学号:",labelside='top',)
  121. top.xh1.pack(side="left")
  122. top.xh1.entry['textvariable']=zxh
  123. top.xq1=tkinter.tix.LabelEntry(top,label="学期:",labelside='top',)
  124. top.xq1.pack(side="left")
  125. top.xq1.entry['textvariable']=zxq
  126. top.jxjdj1=tkinter.tix.LabelEntry(top,label="          奖学金等级:",labelside='top',)
  127. top.jxjdj1.pack(side="left")
  128. top.jxjdj1.entry['textvariable']=zjxjdj

  129. tree.bind('<<TreeviewSelect>>',selectTree)

  130. Savebn=tk.Button(top,text="添加",width=10)
  131. Savebn.bind("<Button-1>",turn_save)
  132. Savebn.pack(side="left")

  133. Updatebn=tk.Button(top,text="修改",width=10)
  134. Updatebn.bind("<Button-1>",table_update)
  135. Updatebn.pack(side="left")

  136. Deletebn=tk.Button(top,text="删除",width=10)
  137. Deletebn.bind("<Button-1>",table_delete)
  138. Deletebn.pack(side="left")

  139. bs=tk.Button(root,text="显示数据",width=10)
  140. bs.bind("<Button-1>",turn_property)
  141. bs.pack(side="left")

  142. root.mainloop()
复制代码

捕获.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-6-30 23:19:15 | 显示全部楼层
数据库没有“学生奖学金信息”这个表哦
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-30 23:21:20 | 显示全部楼层
z5560636 发表于 2021-6-30 23:19
数据库没有“学生奖学金信息”这个表哦

能不能帮忙改改
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-7-1 08:39:31 From FishC Mobile | 显示全部楼层
君苏依寂 发表于 2021-6-30 23:21
能不能帮忙改改

需要改数据库??
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-7-1 08:56:53 From FishC Mobile | 显示全部楼层
wp231957 发表于 2021-7-1 08:39
需要改数据库??

我也不知道该怎么解决,大佬要是有时间的话,能帮忙改一下就改一下,谢谢啦
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-7-1 09:01:27 From FishC Mobile | 显示全部楼层
君苏依寂 发表于 2021-7-1 08:56
我也不知道该怎么解决,大佬要是有时间的话,能帮忙改一下就改一下,谢谢啦

你这是准备干啥呢
你自己有数据库吗
10有89你这代码是拿来主义,所以要玩一玩的话就算了,毕竟你没有库
你要是准备生产用,那你就得根据需要自己编写一个库,然后再去修改代码
数据库这东西别人没办法帮你
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-7-1 10:00:59 From FishC Mobile | 显示全部楼层
wp231957 发表于 2021-7-1 09:01
你这是准备干啥呢
你自己有数据库吗
10有89你这代码是拿来主义,所以要玩一玩的话就算了,毕竟你没有库 ...

多谢批评,这是冷月让我改的,我改了半天也没弄好,上CSDN上搜索说的是相对路径不一样,我也不知道该怎么改,于是我就想上论坛上寻求帮助吧,这个应该是冷月自己写的,应该没有数据库。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-22 01:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表