如何在Tkinter中定义一个变量来链接我的Google表格? [英] How to define a variable to link my google sheets in Tkinter?
问题描述
我正在学习 Tkinter ,我在登录界面中工作,我有两个条目作为我的用户名和密码 *,还有一个我的登录按钮,我为sqlite数据库的条目和登录按钮定义了一个函数,在本地运行良好,但是我想将用户名和密码存储在服务器中,所以我选择使用Google表格API为了创建表格并在其中存储我的用户名和密码,我试图定义一个函数来链接我的条目和登录按钮,但是它不起作用.任何建议提前致谢.祝你有美好的一天.
I'm learning Tkinter and i worked in a login interface, i have two entries for my username and password*, also one button for my login, I've defined a function for my entries and login button with sqlite database and it works good locally, but I want to store my usernames and passwords in a server so i choose to use Google sheets API in order to create a sheet and store there my usernames and passwords, I triede to define a funtion to link my entries and login button but it does'nt work. any advise thanks in advance. have a good day.
#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')
这里我看到的唯一问题是,用户名必须始终为 int
,因此我建议将其更改为 str
,以提高效率.
Here the only problem I see is, username always have to be an int
, so I recommend changing it to str
so that its more efficient.
我不知道为什么将密码从SQLite切换到Google表格都将是不安全的,因为您将密码存储为纯文本,因此建议您先对其进行哈希处理并存储哈希值.至于托管数据库,还有其他在线服务器可以托管MySQL数据库,请此处
I dont know why you switched from SQLite to Google Sheets both will be insecure as you are storing passwords as plaintext, I recommend hashing it pre-hand and storing the hashed values. And as far as hosting of a database is concerned there are other online servers which allow MySQL database to be hosted, take a look here
这篇关于如何在Tkinter中定义一个变量来链接我的Google表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!