0

Нужно сделать так что бы от одна кнопка enter выполняла две функции: 1)Если пользователь не ввёл какие-либо данные то запускала текст(это я сделал) 2)Если всё правильно, то нужно что бы всё окно очищалось и выводились другие слова(Вот в это я и не могу грамотно сделать). Потому что всегда приходится нажимать на кнопку два раза

from tkinter import *
from tkinter import messagebox
user_dict = {}
root = Tk()
class User:
    def __init__(self, name):
        self.name = name
        self.password = None

def check(event):# Проверка наличия всех данных
    n = login.get()
    p = password.get()
    if n and p:
        text_lol.pack()
        text_lol.place(x = 100, y = 195)
        enter.bind('<Button - 1>',next_1,next_2)
    if not n and p:
        text_not_ok_login.pack()
        text_not_ok_login.place(x = 20, y = 100)
    elif not p and n:
        text_not_ok_password.pack()
        text_not_ok_password.place(x = 20, y = 165)

def next_1(event):
    destroy_object = [text_parc,text_login,text_password,text_not_ok_login,login,password,enter,text_not_ok_password,enter,text_lol]
    for object_name in destroy_object:
        object_name.destroy()

def next_2(event):
    text_login2.pack()
    text_login2.place(x = 20, y = 50)


root.geometry('300x450')
root.title('Войти в cиcтему')
root['bg'] = 'white'
text_lol = Label(text = ' - Нажми ещё раз', font = 'Consalas 10', fg = 'black', bg = 'white')

text_parc = Label(text = 'Вход в парсер', font = 'Consalas 25', fg = 'black', bg = 'white')

text_login = Label(text = 'Логин', font = 'Consalas 10', fg = 'black', bg = 'white')
login = Entry(root, font = 'Consalas 15', fg = 'black', bg = 'white')
text_login2 = Label(text = 'Логин', font = 'Consalas 10', fg = 'black', bg = 'white')

text_password = Label(text = 'Пароль', font = 'Comfortaa 10', fg = 'black', bg = 'white')
password = Entry(root, font = 'Consalas 15', fg = 'black', bg = 'white',show = '*')

enter = Button(text='Войти ', font = 'Consalas 15', fg = 'white', bg = '#0000FF')
enter.bind('<Button - 1>',check)

text_not_ok_login = Label(text = 'Вы не ввели логин', font = 'Consalas 7', fg = 'red', bg = 'white')
text_not_ok_password = Label(text = 'Вы не ввели пароль', font = 'Consalas 7', fg = 'red', bg = 'white')

text_parc.pack()
text_login.pack()
text_parc.place(x = 20, y = 5)
text_login.place(x = 20, y = 50)
login.pack()
login.place(x = 20, y = 70)
text_password.pack()
password.pack()
text_password.place(x = 20, y = 115)
password.place(x = 20, y = 135)
enter.pack()
enter.place(x = 20, y = 190)
root.mainloop()
1
  • Ну, смотрите, если вам надо сделать 2 функции для одной кнопки, то надо одну привязать как параметр command в самой кнопке, а вторую просто забиндить.
    – DGDays
    23 мая 2020 в 22:34

1 ответ 1

0

Вам нужно просто в ветке if n and p вызвать нужные функции

if n and p:
    next_1()
    next_2()

И в функции next_1() и в next_2 убрать аргумент event, тк он здесь не нужен

Ваш ответ

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

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