Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用raspberry pi 3中的easygui连接数据库mysql的登录系统_Python_User Interface_Easygui - Fatal编程技术网

Python 使用raspberry pi 3中的easygui连接数据库mysql的登录系统

Python 使用raspberry pi 3中的easygui连接数据库mysql的登录系统,python,user-interface,easygui,Python,User Interface,Easygui,我开始使用GUI。我的第一个项目是使用raspberry pi 3中的easygui实现连接到数据库mysql的登录系统。我已经做了输入密码的编码,但我不知道如何连接到数据库,而按下ok按钮。当我运行编码时,它将在cmd上显示密码和用户名。我不知道如何设置它与数据库 这是我的代码: import easygui as eg msg = "Enter logon information" title = "Demo of multpasswordbox" fieldNames = ["User

我开始使用GUI。我的第一个项目是使用raspberry pi 3中的easygui实现连接到数据库mysql的登录系统。我已经做了输入密码的编码,但我不知道如何连接到数据库,而按下ok按钮。当我运行编码时,它将在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

您正在将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]

可以我已经把密码。。然后我想把它连接到mysql..我给你看代码..当我运行代码..我会弹出,但它没有连接到mysql,它不能连接到数据库mysql
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()