как получить данные из виджета ввода - PullRequest
0 голосов
/ 18 января 2020

Я хочу, чтобы моя программа получала информацию из виджета ANS и использовала ее в статистике if и elif

def goal (): root1 = Tk ()

first_p_x = random.randint(1, 50)
first_p_y = random.randint(1, 50)
second_p_x = random.randint(1, 50)
second_p_y = random.randint(1, 50)

Label(root1, text=f'what is the slope of these two points ( {first_p_x} , {first_p_y} ) ( {second_p_x} , {second_p_y} )').grid(row=0, column=0, sticky='e')
ans = Entry(root1, width=30).grid(row=0, column=1,
                            padx=2, pady=2, sticky='we', columnspan=9)

delta_y = first_p_y - second_p_y
delta_x = first_p_x - second_p_x
a = Fraction(delta_y, delta_x)

if ans == 'help':
    Label(root1, text=f"so first you set up the problem as {first_p_y}-{second_p_y} over {first_p_x}-{second_p_x}").grid(row=2, column=0, sticky='e')
    Entry(root1, width=30).grid(row=2, column=1,
                            padx=2, pady=2, sticky='we', columnspan=9)

elif ans == a:
    Label(root1, text="Thats correct nice job").grid(row=1, column=0, sticky='e')

Button(root1, text="Submit", width=15, command=root1.destroy).grid(row=3, column=1, sticky='e', padx=2, pady=2)

1 Ответ

1 голос
/ 18 января 2020

вы можете использовать метод .get (), вот пример, вам нужно добавить кнопку ввода, как показано в коде ниже

def ans_func():
    ans_data = ans.get()
    if ans_data == 'help'
        #your function
    elif:
        #your function

и к кнопке add command = 'ans_fun c'

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...