Я пытаюсь дать себе упражнения, используя импорт и храня программы и модули отдельно друг от друга. В этом конкретном упражнении, которое я дал себе, у меня есть конвертер базисных c футов в дюймы и дюймов в футы.
Все работает, кроме одной проблемы. Там, где ответ отображается в GUI, новый ответ покрывает старый ответ, а не заменяет его.
import tkinter as tk
from tkinter import E, W
import Converter
window = tk.Tk()
window.title("Converter")
answer_label = tk.Label(window, text="No Answer")
answer_label.grid(row=5)
def feet_to_inches_function(old_label):
old_label.grid_forget()
answer_label = tk.Label(window, text=Converter.feet_to_inches(int(entry_bar.get())))
answer_label.grid(row=5)
def inches_to_feet_function(old_label):
old_label.grid_forget()
answer = tk.Label(window, text=Converter.inches_to_feet(int(entry_bar.get())))
answer.grid(row=5)
title_label = tk.Label(window, text="Convert")
entry_bar = tk.Entry(window, font=('HELVETICA', 10))
fti_button = tk.Button(window, text="Feet to Inches", command=lambda: feet_to_inches_function(answer_label))
itf_button = tk.Button(window, text="Inches to Feet", command=lambda: inches_to_feet_function(answer_label))
quit_button = tk.Button(window, text="Quit", command=window.destroy)
title_label.grid(row=0, column=0, sticky=W)
entry_bar.grid(row=1, columnspan=2, sticky=(E, W))
fti_button.grid(row=3, column=0)
itf_button.grid(row=3, column=1)
quit_button.grid(row=4, columnspan=2, sticky=(E, W))
window.mainloop()
Также как отдельный вопрос мне трудно разобраться в mainl oop .Я знаю, что она превращает программу go в бесконечное число l oop, но откуда? Я не вижу никаких логических доказательств того, что мой код бесконечен l oop.
Большое спасибо