【问题标题】:How can I make a password with if and the text of a label?如何使用 if 和标签文本设置密码?
【发布时间】:2021-06-22 02:28:43
【问题描述】:

我做了一个命令,当按下一个按钮时,一个文本被添加到一个标签上,我想要实现的是,如果你输入正确的组合,然后按下一个按钮确认,然后一个窗口打开一些我稍后会选择的文本。 问题是,我不知道如何从实验室制作文本来制作 if :( 如何使“trad”中的文本成为密码?

def salir():
    if 

def a():
    trad.config(text=trad["text"]+"ar.")

def b():
    trad.config(text=trad["text"]+"ab.")
    
def i():
    trad.config(text=trad["text"]+"iz.")
    
def d():
    trad.config(text=trad["text"]+"de.")
    


ventana=tk.Tk()
ventana.title("Bosque")
ventana.geometry('900x800')
ventana.resizable(0,0)

frame = tk.Frame(ventana)
frame.pack()

canvas = tk.Canvas(frame, width=900, height=800)
canvas.pack()

leta = ""

trad = tk.Label(ventana,text=leta,wraplength=220,anchor="n")
trad.config(bg="#137420", fg="#E59866",font=("Verdana",10,"bold","italic"),width=25, height=9)
trad.place(x=660,y=160)

#caja = tk.Entry(ventana, width=37)
#caja.place(x=660,y=200)


boton = tk.Button(text="  ↑  ",font=("Verdana",17), command=a)
boton.config(bg="#135C3F", fg="#D7D731")
boton.place(x=745,y=330)

boton1 = tk.Button(text="  ↓  ",font=("Verdana",17), command=b)
boton1.config(bg="#135C3F", fg="#D7D731")
boton1.place(x=745,y=423)

boton2 = tk.Button(text="  Ir  ",font=("Verdana",16), command=salir)
boton2.config(bg="#135C3F", fg="#D7D731")
boton2.place(x=746,y=379)

boton3 = tk.Button(text=" → " ,font=("Verdana",17), command=d)
boton3.config(bg="#135C3F", fg="#D7D731")
boton3.place(x=812,y=376)

boton4 = tk.Button(text=" ← ",font=("Verdana",17), command=i)
boton4.config(bg="#135C3F", fg="#D7D731")
boton4.place(x=686,y=376)
ventana.mainloop()

【问题讨论】:

  • 您能否详细说明您的问题。
  • 如何使“trad”中的文本成为密码?

标签: python python-3.x if-statement tkinter


【解决方案1】:

这是你想要的吗?我做了我能理解的。

from tkinter import messagebox as msg
def salir():
    global posx    #variables de alcance para todo el script no solo la función
    global posy
    global ima

    if trad["text"]!="ar.de.ab.iz.ar.iz.ab.de.":
        msg.showerror("Error","Incorrect Password")
        trad.config(text="")
    else:
        new_windw=tk.Toplevel()

【讨论】:

  • 哦,原来如此,非常感谢:D
  • 我想我错了,我想要实现的是文本是定义的文本,如果你写“ar.de.ab”。然后会出现一个窗口,但如果没有,则会出现另一个窗口,提示重试
  • 是的,那么 messagebox 正在这样做。 @Leandro
  • 嘿,我还有一个问题,我试图输入一个“Elif”,但它不起作用:(这个:||||| elif trad"text"]=="ar.ab.iz .": |||||
  • 你忘记了[
猜你喜欢
  • 1970-01-01
  • 2017-11-07
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-27
相关资源
最近更新 更多