"选择联系人来自表格,其中名称='名称'"

时间:2015-12-12 15:25:14

标签: python mysql tkinter

我正在尝试使用python中的Tkinter和Mysql构建一个简单的房屋贷款申请。我的功能基本上是希望用户键入姓名和联系号码,并获取联系号码表格数据库以匹配联系中的用户密钥。但我面临的问题是当我插入的名称是正确的,我无法从数据库。我的命令有任何问题

sql = "SELECT 'Contact' FROM `table` WHERE Name = 'name'"

以下是整个代码

from Tkinter import *
from tkMessageBox import *
from sys import exit
import MySQLdb
import os





class application(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        self.master= master
        self.L1 = Label(self,text="Application Loan")
        self.L1.pack(side=TOP)
        self.L2 = Label(self, image=logo).pack(side=LEFT)
        self.B1 = Button(self, text="car loan",command = self.car_loan)
        self.B1.pack(side = LEFT)
        self.L3 = Label(self,image=logo1).pack(side=RIGHT)
        self.B2 = Button(self, text="house loan", command = self.house_loan)
        self.B2.pack(side=BOTTOM)

def house_loan(self):
    self.house = Tk()
    self.house.title("house loan")
    self.house.L12 = Label(self.house, text="Thank you for choosing us. Please left your contact number, our staff will contact you for more detail")
    self.house.L12.pack(side=TOP)
    self.house.L6= Label(self.house, text="Name").pack()
    self.house.E8 = Entry(self.house,textvariable=.var1)
    self.house.E8.pack()
    self.house.L7= Label(self.house, text="Contact").pack()
    self.house.E9 = Entry(self.house,textvariable=var4)
    self.house.E9.pack()
    self.house.B4=Button(self.house,text="submit",command=self.Thankyou)
    self.house.B4.pack()

def Thankyou(self):
    name = self.house.E8.get()
    print name
    #global Contact
    global Contact
    Contact = NONE
    self.db = MySQLdb.connect("localhost","root","","bank" )
    cursor =self.db.cursor()
    sql = "SELECT 'Contact' FROM `table` WHERE Name = 'name'"
    print Contact
    cursor.execute(sql)
    input=self.house.E9.get()
    print input
    results = cursor.fetchall()
    for row in results:

        Name = row[0]
        Age = int(row[1])
        Monthly_income = int(row[2])
        Contact = row[3]
        Email = row[4]

    if(input != Contact):
        sql = "UPDATE table SET Contact = 'input' \
        WHERE NAME = 'var1'"
        showinfo("Your contact number was updated","Our staff will contact you as soon as possible")

    else:
        showinfo("Thank you","Our staff will contact you as soon as possible")

    cursor.close()
    self.db.commit()

if __name__ == "__main__" :
table='table'
root = Tk()
root.title("Loan Application")

global logo
global logo1
var1 = StringVar()
var2 = IntVar()
var3= IntVar()
var4 = IntVar()
logo = PhotoImage(file = 'car.gif').subsample(3,3)
logo1 = PhotoImage(file = 'house1.gif').subsample(3,3)
application(root).pack(expand=TRUE)
root.mainloop()

print contact no none(当我输入db中存在的正确名称时) 我尝试取消contact = none但它会给我错误显示

NameError: global name 'Contact' is not defined

我不知道出了什么问题。有人可以帮忙吗?

0 个答案:

没有答案