【发布时间】:2021-06-29 16:30:24
【问题描述】:
我的代码显示 AttributeError: 'Label' 对象没有属性 'get'。我已经使用了所有可以联系到的可用资源,但无事可做。如果有人能花一分钟时间帮助我,我会很高兴。错误在第 67 行,上面写着:Email = Label(root, text='Email/USER ID', font = ('consolas',13))。阿里加托
from tkinter import *
from tkinter import messagebox
import mysql.connector
global root
root = Tk()
root.geometry("350x450")
root.title("LOGIN")
root.resizable(0,0)
j=0
g=0
for i in range(100):
c = str(222222+g)
Frame(root, width=10, height=450,bg="gray").place(x=j, y=0)
j = j + 10
g = g + 1
Frame(root, width=250, height=350).place(x=50, y=50)
#============VARIABLES==========
Email = StringVar()
Password = StringVar()
#===============================
#Label Username/Email
Email = Label(root, text='Email/USER ID', font = ('consolas',13))
Email.place(x=80, y=170)
e = Entry(root, width=20, font = ('consolas',13))
e.place(x=80, y=200)
#Label password
Password = Label(root, text='Password', font = ('consolas',13))
Password.place(x=80, y=230)
e1 = Entry(root, width=20, font = ('consolas',13), show = '*')
e1.place(x=80, y=260)
stayButton = Checkbutton(root, text = "Remember Password")
stayButton.place(x=80, y=300)
def Database():
global conn, cursor
conn = mysql.connector.connect(host="localhost", user="root", passwd="", db="myPython")
cursor = conn.cursor()
def login():
Database()
ee = Email.get()
pp = Password.get()
if ee == "" or pp =="":
messagebox.showinfo("Alert!","Enter your Email/Password")
else:
cursor.execute("SELECT * FROM `user` WHERE 'email' = %s", [ee])
if cursor.fetchone() is not None:
messagebox.showinfo("Alert", "Username already in use")
else:
cursor.execute("INSERT INTO `user` (email, password) VALUES (%s, %s)", (str(ee)))
conn.commit()
Email.set("")
Password.set("")
messagebox.showinfo("Meassage", "Logged in Successfully")
cursor.close()
conn.commit()
Button(root, width=10, height=1, border=0, fg="white", bg="gray", command=login, text="SIGN IN").place(x=135, y=335)
b1=Button(root, width=10, height=1, border=0, fg="white", bg="gray", text="SIGN UP").place(x=135, y=370)
root.mainloop()
【问题讨论】:
-
你希望这个
get方法做什么?
标签: python python-3.x tkinter