intvar mysql_如何修复mysql python中的“TypeError:an integer is required(get type IntVar)”

我试图在我的数据库表中插入日期。但我有

Traceback (most recent call last):

File "D:\SchoolApp\Python\lib\tkinter\__init__.py", line 1705, in __call__

return self.func(*args)

File "D:/SchoolApp/Python/register only.py", line 45, in register

self.entry_birthday = datetime.datetime(self.birth_day)

TypeError: an integer is required (got type IntVar)

self.get_birthday

int(self.get_birthday)

import tkinter as tk

import pymysql

from tkinter import *

from tkinter import messagebox

import datetime

class Main(tk.Frame):

def __init__(self, master, *args, **kwargs):

tk.Frame.__init__(self, master, *args, **kwargs)

self.master = master

master.title("Thesis")

self.register_button = Button(master, text="Register", command=self.register)

self.register_button.pack()

self.db = pymysql.connect(host = "localhost",user = "root",passwd = "",db = "database")

self.cursor = self.db.cursor()

self.QueryResident = "CREATE TABLE IF NOT EXISTS residence (BIRTH_DATE date, AGE varchar(255)not null)"

self.cursor.execute(self.QueryResident)

def registered(self,birth_day):

self.get_birth_day =self.birth_day.get()

if (self.get_birth_day == ""):

messagebox.showerror("Error!","Please complete the required field")

else:

self.cursor.execute ("INSERT INTO residence (BIRTH_DATE) VALUES(%s)",(self.get_birth_day))

self.db.commit()

messagebox.showinfo("Success!","Registration successful")

self.cursor.close()

self.db.close()

def register(self):

self.master_register = Toplevel()

self.birth_day = IntVar()

self.label_birthday = Label(self.master_register, text = "Birth Day")

self.label_birthday.pack()

self.entry_birthday = Entry(self.master_register, textvariable = self.birth_day)

self.entry_birthday = datetime.datetime(self.birth_day)

self.entry_birthday.pack()

self.button_submit = Button(self.master_register, text = "Submit", command = lambda: self.registered(self.birth_day))

self.button_submit.pack()

我的预期输出是输入的日期get将以任何日期格式存储到数据库中,我将根据出生日期计算年龄。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值