【发布时间】:2022-01-19 19:13:12
【问题描述】:
我试图让用户输入一个名称以检查名称列表,但是我不确定如何存储用户输入以在白名单函数中使用。我尝试在白名单中使用 if e:但它不起作用,我应该在 if 子句中添加什么?或者有没有其他解决方案
from tkinter import Message
from tkinter import *
import pandas as pd
from openpyxl import load_workbook
root = Tk()
root.geometry('400x200')
#Excel sheet being used
book = load_workbook('Desktop\python\excel.xlsx')
#Active sheet
sheet = book['names']
whitelist = set(row[0].value for row in sheet.rows)
#User input name to check for whitelist
e = Entry(root, width=20)
e.pack()
#Condition to check if user is whitelisted
def whitelist():
if e in whitelist:
print("User is whitelisted")
else:
print("The user is not whitelisted")
button = Button(root, text="Check", command=whitelist)
button.pack()
root.mainloop()
【问题讨论】:
-
您将名称
whitelist用于函数和集合。它一次只能引用其中之一。 -
代码编辑后现在可以工作了,感谢您的帮助!
-
不要用有效的解决方案编辑问题。