用easygui在raspberrypi3中实现与数据库mysql连接的登录系统

2024-09-30 04:39:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始使用GUI。我的第一个项目是在raspberry PI3中使用easygui做一个连接到数据库mysql的登录系统。我已经做了输入密码的编码,但我不知道如何连接到数据库,而按确定按钮。当我运行编码时,它将在cmd处显示密码和用户名。我不知道如何用数据库设置它。你知道吗

这是我的代码:

import easygui as eg

msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["User ID", "Password"]
fieldValues = []  # we start with blanks for the values
fieldValues = eg.multpasswordbox(msg,title, fieldNames)

# make sure that none of the fields was left blank
while 1:
  if fieldValues == None: break
  errmsg = ""
  for i in range(len(fieldNames)):
    if fieldValues[i].strip() == "":
      errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
  if errmsg == "": break # no problems found
  fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)
print "Reply was:", fieldValues

Tags: ofthe数据库密码编码foriftitle
2条回答

您将FieldValue创建为一个空列表,用于存储输入。输入按创建字段的顺序存储在代码中:

import easygui as eg

msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["User ID", "Password"]
fieldValues = []  # we start with blanks for the values
fieldValues = eg.multpasswordbox(msg,title, fieldNames)

userID = fieldValues[0]
password = fieldValues[1]
from easygui import *
import mysql.connector

TITLE = "Enter logon information"
conn = ""
table = ""

def Login():
    global conn
    conn = mysql.connector.connect(host='localhost',user='pi',password='1234',db='mydb')
    cursor = conn.cursor()

    msg = "Enter logon information"
    title = "Login"
    fieldNames = ["Usercode","Password"]
    fieldValues = []
    fieldValues = multpasswordbox(msg,title,fieldNames)
    usercode, password = fieldValues[0], fieldValues[1]
    sql = "SELECT * FROM `data` WHERE usercode = %s AND password = %s"
    cursor.execute(sql,(usercode,password))
    results = cursor.fetchall()


Login()

相关问题 更多 >

    热门问题