|
50鱼币
# -*- coding:utf-8 -*-
"""
@TODO :
@Time :
@Author :
"""
import threading
import tkinter
from tkinter import ttk
from tkinter.ttk import Label
import dyh_Connect_database
from tkinter.messagebox import showinfo
import pymysql
import dyh_menu,center
class Add_group:
def thread_it(func, *args):
'''将函数打包进线程'''
# 创建
t = threading.Thread(target=func, args=args)
# 守护 !!!
t.setDaemon(True)
# 启动
t.start()
# 阻塞--卡死界面!
def __init__(self,root1):
self.root1 = root1
self.group_name = tkinter.StringVar()
group_name = Label(root1, font=('宋体', 25), text='学 号:').grid(row=1, column=1,padx=20) # 账号
group_name_input_box = tkinter.Entry(root1, textvariable=self.group_name, font=('宋体', 25)).grid(row=1,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.group_id = tkinter.StringVar()
group_id = Label(root1, font=('宋体', 25), text='姓 名:').grid(row=2, column=1) # 账号
group_id_input_box = tkinter.Entry(root1, textvariable=self.group_id, font=('宋体', 25)).grid(row=2,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.registration_status = tkinter.StringVar()
registration_status = Label(root1, font=('宋体', 25), text='志愿者编号:').grid(row=4, column=1,padx=20) # 账号
registration_status_input_box = tkinter.Entry(root1, textvariable=self.registration_status, font=('宋体', 25)).grid(row=4,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.group_address = tkinter.StringVar()
group_address = Label(root1, font=('宋体', 25), text='专 业:').grid(row=5, column=1) # 账号
group_address_input_box = tkinter.Entry(root1, textvariable=self.group_address, font=('宋体', 25)).grid(row=5,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.Competent_unit_type = tkinter.StringVar()
Competent_unit_type = Label(root1, font=('宋体', 25), text='班 级:').grid(row=6, column=1) # 账号
Competent_unit_type_input_box = tkinter.Entry(root1, textvariable=self.Competent_unit_type, font=('宋体', 25)).grid(row=6,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.group_region = tkinter.StringVar()
group_region = Label(root1, font=('宋体', 25), text='年 龄:').grid(row=7, column=1) # 账号
group_region_input_box = tkinter.Entry(root1, textvariable=self.group_region, font=('宋体', 25)).grid(row=7,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.Service_type = tkinter.StringVar()
Service_type = Label(root1, font=('宋体', 25), text='电 话:').grid(row=8, column=1) # 账号
Service_type_input_box = tkinter.Entry(root1, textvariable=self.Service_type, font=('宋体', 25)).grid(row=8,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
self.Contact_name = tkinter.StringVar()
Contact_name = Label(root1, font=('宋体', 25), text='志愿总时长:').grid(row=9, column=1) # 账号
Contact_name_input_box = tkinter.Entry(root1, textvariable=self.Contact_name, font=('宋体', 25)).grid(row=9,column=2,pady=10) # 账号输入框,把textvariable属性设置为StringVar()
'''ttk自定义按钮风格'''
s = ttk.Style()
s.configure('my.TButton', font=('宋体', 20))
add_button=ttk.Button(root1, text='添加', style="my.TButton", width=30, command=lambda: self.thread_it(self.add_v())).grid(row=10, column=1,columnspan=2, ipady=10) #登录按钮
def add_v(self):
conn = dyh_Connect_database.connext()
Name = self.group_name.get()
Id = self.group_id.get()
Status = self.registration_status.get()
Address = self.group_address.get()
Competent = self.Competent_unit_type.get()
Region = self.group_region.get()
Service = self.Service_type.get()
Contact = self.Contact_name.get()
cursor = conn.cursor()
sql = "INSERT INTO groups values ('%s','%s','%s','%s','%s','%s','%s','%s')" % (Name, Id, Status, Address, Competent, Region, Service, Contact)
print(sql)
cursor.execute(sql)
conn.commit() # 提交数据
print("info", showinfo("提示", "添加成功"))
self.root1.destroy() # 关闭窗口
dyh_menu.menu() # 跳转到菜单窗口
def add_group():
root1 = tkinter.Tk() #创建tkinter页面
width = 625
height = 600
screen_width = root1.winfo_screenwidth()
screen_height = root1.winfo_screenheight()
root1.geometry(center.tk_center(width, height, screen_width, screen_height)) # 长x宽+x+y
root1.title('增加志愿者信息') # 标题
p2=Add_group(root1)
root1.mainloop()
报错信息
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups values ('gwhu','ytu','bjkwt','twyu','bnmgj','jlkt','fhgwe','567')' at line 1")
试试 sql 这里代码改成这样:
sql = "INSERT INTO groups values (%s, %s, %s, %s, %s, %s, %s, %s)"
cursor.execute(sql, (Name, Id, Status, Address, Competent, Region, Service, Contact))
|
|