0
x = Label(бла бла бла)

if x['text length=5']:
    и так далее

Чтобы можно было проверять длину текста.

2 ответа 2

2

Метод cget позволяет получить значение любой из настроенных опций.

from tkinter import *


root = Tk()
root.title("Password Generator")
root.geometry('600x400')
root.configure(background ="gray")

def gen():
    len_t1 = len(t1.cget("text"))                                      # <----
    len_t2 = len(t2.cget("text"))                                      # <----
    print(f'{len_t1}') 
    print(f'{len_t2}')                                  

    if len_t1 > 5:
        print('Hello') 
        
    if len_t2 == 9:
        print('World')     


t1 = Label(root, text='Password Generator', font=('Arial', 25), fg='green', background="gray")
t1.place(x=60,y=0)
t2 = Label(root,text='Password:',font=('Arial',14),background ="gray")
t2.place(x=145,y=90)


b = Button(root,text='Generate!',font=('Arial',14), fg='green',background="gray", command=gen)
b.place(x=230,y=195)

root.mainloop()

введите сюда описание изображения

1
if len(x['text']) == 5:
    бла бла бла

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.