tkinter - 如何修复“在封闭范围内分配之前引用的自由变量'db_username'”
问题描述
我刚开始学习 python,我很擅长制作没有 GUI 的程序,但我一直在使用它们并且没有 tkinter,我的 pymysql 代码工作得很好,但是当我开始使用 tkinter 时,它不像没有它那样工作,我在分配之前一直被引用无论我尝试了多少不同的格式\组织,它仍然无法正常工作,完整代码“ https://pastebin.com/04uFWB1R ”
就像我说的那样,没有 gui 就可以正常工作,但是一旦我用 gui 尝试它就行不通
def lClick():
__uID = uID.get()
__uName = uName.get()
__passW = passW.get()
print(__uName)
print(__passW)
auth = Label(lWindow, text="Authorizing...",font=("Areial Bold", 10))
auth.place(x=-10,y=99)
time.sleep(0.5)
time.sleep(1)
def authorize():
if __uID == "01":
auth.configure(text='''
User Authenticated...
Accessing Database
''')
##############################################################
def dbCon():
con = pymysql.connect(host='192.***.***.**',
user='****',
password='******',
db='python1',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
with con:
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE 'id' = '{0}'".format(__uID))
rows = cur.fetchall()
for row in rows:
db_username = row['username']
db_password = row['password']
def logon():
if __uName == db_username:
auth.configure(text="DataBase Connected")
else:
auth.configure(text="Error Has Occured")
logon()
dbCon()
else:
auth.configure(text="Not Authorized")
authorize()
我试图弄清楚如何修复“分配前引用的变量”错误
解决方案
推荐阅读
- java - 单击关闭下拉菜单时如何查找元素定位器
- c# - 不了解 wpf 更新动态创建的图像控件可见性每秒变化的行为
- javascript - 使用 .reduce 对每个名称求和
- firebase - Firestore 安全规则:无法检查子集合中的文档是否等于用户 UID
- python - 如何合并具有相同索引的两个文件中的字符串?
- c# - 在 Unity 中无意中破坏了 BoxCollider
- javascript - 如何使用 .join .slice 或 .push 使这个加密器/解密器工作?
- php - 的程序含义?与否?
- ruby-on-rails - 如何通过单个控制器创建具有两个模型的两个记录(多步骤形式)
- python-2.7 - 仅当平台为 Windows 时才安装 python 依赖项