如何在 Tkinter 中为 link 我的 google 工作表定义变量?
How to define a variable to link my google sheets in Tkinter?
我正在学习 Tkinter 并且我在登录界面工作,我的 用户名有两个 条目 和密码*,也是我的登录的一个按钮,我已经用sqlite数据库为我的条目和登录按钮定义了一个函数,它在本地运行良好,但我想要将我的用户名和密码存储在服务器中,所以我选择使用 Google sheets API 来创建一个 sheet 并将我的用户名和密码存储在那里,我试过为 link 我的条目和登录按钮定义一个函数,但它不起作用。任何建议提前感谢。祝你有美好的一天。
#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
,这样效率更高。
我不知道你为什么从 SQLite 切换到 Google 工作表,因为你将密码存储为明文,所以两者都不安全,我建议预先对其进行散列处理并存储散列值。就数据库托管而言,还有其他在线服务器允许托管 MySQL 数据库,请查看 here
我正在学习 Tkinter 并且我在登录界面工作,我的 用户名有两个 条目 和密码*,也是我的登录的一个按钮,我已经用sqlite数据库为我的条目和登录按钮定义了一个函数,它在本地运行良好,但我想要将我的用户名和密码存储在服务器中,所以我选择使用 Google sheets API 来创建一个 sheet 并将我的用户名和密码存储在那里,我试过为 link 我的条目和登录按钮定义一个函数,但它不起作用。任何建议提前感谢。祝你有美好的一天。
#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
,这样效率更高。
我不知道你为什么从 SQLite 切换到 Google 工作表,因为你将密码存储为明文,所以两者都不安全,我建议预先对其进行散列处理并存储散列值。就数据库托管而言,还有其他在线服务器允许托管 MySQL 数据库,请查看 here