Python 如何定义一个变量来链接Tkinter中的google工作表?

Python 如何定义一个变量来链接Tkinter中的google工作表?,python,python-3.x,tkinter,google-sheets-api,tkinter-entry,Python,Python 3.x,Tkinter,Google Sheets Api,Tkinter Entry,我正在学习Tkinter,我在一个登录界面中工作,我有两个用户名和密码条目*,还有一个登录按钮,我已经为我的条目和登录按钮定义了一个函数,使用sqlite数据库,它在本地运行良好,但是我想在服务器上存储我的用户名和密码,所以我选择使用GoogleSheetsAPI来创建一个表单并在那里存储我的用户名和密码,我试图定义一个函数来链接我的条目和登录按钮,但它不起作用。任何建议,请提前谢谢。祝你今天愉快 #THIS IS MY FUNCTION PART def logear(): sco

我正在学习Tkinter,我在一个登录界面中工作,我有两个用户名和密码条目*,还有一个登录按钮,我已经为我的条目和登录按钮定义了一个函数,使用sqlite数据库,它在本地运行良好,但是我想在服务器上存储我的用户名和密码,所以我选择使用GoogleSheetsAPI来创建一个表单并在那里存储我的用户名和密码,我试图定义一个函数来链接我的条目和登录按钮,但它不起作用。任何建议,请提前谢谢。祝你今天愉快

#THIS IS MY FUNCTION PART

def logear():

    scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
             "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
    creds = ServiceAccountCredentials.from_json_keyfile_name("testsheetsxxxxx.json", scope)

    client = gspread.authorize(creds)

    sheet = client.open("testing").sheet1    ########'testisng is my google sheet and 'sheet1' is what im 
                                                      using to store usernames and passwords###########

    user = entry_usuario.get()              ####entry_usuario is my username entry########
    contra = entry_contrasena.get()         ####entry_contrasena us my password entry######

    c = #####stucked here####

    if ####stucked here####:
        messagebox.showinfo(title='login correcto', message='usuario y contraseña correctos')
    else:
        messagebox.showerror(tittle=None, message='Contraseña Incorrecta') 

以下是对我有效的方法:

def logear():
    # Rest of required code 
    user = entry_usuario.get() 
    contra = entry_contrasena.get()
    for i in c: # Loop through the list
        if int(user) == i['contraseña'] and contra == i['password']:  # Check if password and username exists in the dict
            messagebox.showinfo(title='login correcto', message='usuario y contraseña correctos')
            break
    else:
        messagebox.showerror(tittle=None, message='Detalles incorrectos')
这里我看到的唯一问题是,username总是必须是
int
,因此我建议将其更改为
str
,以便更有效


我不知道为什么您从SQLite切换到Google Sheets这两种方式都不安全,因为您将密码存储为纯文本,我建议您预先对其进行散列并存储散列值。至于数据库的托管,还有其他允许托管MySQL数据库的在线服务器,看一看

我不太明白,你面临的问题是什么?@CoolCloud我不知道如何定义我的函数“logear”,以便将其与我的条目和登录按钮相链接,我正在使用Google sheets API存储我的“用户名”和“密码”,您如何检索用户名和密码。@CoolCloud我已经定义了
c=sheet.get_all_records()
,在我的sheet1中有两列用户名和密码,在使用sqlite3之前,它在本地运行良好,但是现在我使用的是Google sheets API,我对定义def logear()感到很困惑:
print(c)
give是什么?谢谢你!,现在它工作得更好了,当我输入用户名时,它工作得很好,但我认为密码输入不起作用,即使输入正确的用户名和错误的密码,它也会显示“正确的用户名和密码”@Paul抱歉,我手动键入了代码,应该是
而不是
,我更新了答案,再试一次。它现在运行得很好,伙计,但是我没有把
int
作为
int(user)
,我一直在使用
,因为我刚刚意识到为什么我的密码不能正常工作,因为在我的工作表中它是数字,出于某种原因,我的tkinter条目没有得到它,甚至修改我的工作表并给它一个密码“没有格式的文本”和“数字格式”根本不起作用,但没关系,我可以使用字母数字密码,我真的很感谢你花了这么多时间来帮助我,祝你愉快!我忘记了一些事情,伙计!一旦我的登录用户名和密码正确,我想打开一个新的tkinter文件mainformuser.py我应该使用我的
def logear():
function或使用相同的按钮定义一个新函数?,我在
if int(user)==I['contraseña']和contra==I['password']之后尝试了这个方法:
我使用了
其他:mainformuser.pack
psdt:首先我导入了mainformuser这是我的错,是
mainformuser.py
,好吧,我要问一个新问题,谢谢