from tkinter import*
import sqlite3
class login:
def __init__(self,root):
self.root=root
self.root.geometry("250x250")
self.root.title("Login")
self.root.resizable(False,False)
self.var_username=StringVar() ##variables
self.var_password=StringVar()
username=Label(self.root,text="Username",font=("Bahnschrift SemiBold",15),bg="white",fg="black").place(x=15,y=20)
username=Entry(self.root,textvariable=self.var_username,font=("Bahnschrift SemiBold",15),bg="white",fg="black").place(x=125,y=20,width=115)
password=Label(self.root,text="Password ",font=("Bahnschrift SemiBold",15),bg="white",fg="black").place(x=15,y=60)
password=Entry(self.root,textvariable=self.var_password,font=("Bahnschrift SemiBold",15),bg="white",fg="black").place(x=125,y=60,width=115)
_exit=Button(self.root,text="exit",command=self.destroy,font=("Bahnschrift SemiBold",15),bg="green",fg="white",cursor="hand2").place(x=125,y=100,width=55,height=28)
if __name__ == "__main__":
root=Tk()
obj=login(root)
root.mainloop()
它出現了一個屬性錯誤,我不確定如何修復它,因為它適用于其他代碼段。
uj5u.com熱心網友回復:
您可能希望將按鈕命令從 更改self.destroy為self.root.destroy。
Button(self.root,
text="exit",
command=self.root.destroy,
font=("Bahnschrift SemiBold",15),
bg="green",
fg="white",
cursor="hand2").place(x=125, y=100, width=55, height=28)
作為旁注,doinglabel = Label(root, ...).place(x=...)不會做任何事情(對于任何小部件)。的值label將被存盤為None,以后您將無法參考它來更改其屬性。如果這是目標,那么簡單地說:Label(root, ...).place(x=...)會起作用。否則,您必須在一行中創建小部件,然后將它們放在下一行
PS:建議的做法還包括所面臨的錯誤,以便于診斷。請參考如何提出進一步的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/425256.html
標籤:Python 数据库 sqlite tkinter 按钮
上一篇:如何測量用戶按住按鈕的時間?
