我正在尝试编写一个简单的转换器,它接受条目条目编号,当您单击计算按钮时,它会使用公式进行计算。如果没有 get,它不会转换为 int,但是一旦我绑定 get,所有输入字段都会从程序窗口中消失。有谁对如何克服这个有任何想法?
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Конвертор")
root.geometry("700x600")
class Window(Tk):
def __init__(self):
super().__init__()
def new_window():
window = Tk()
window.title("Листы в киллограммы")
window.geometry("700x600")
label0 = ttk.Label(window, text="Листы в кг.")
label0.pack(anchor="center", padx=20, pady=10)
label1 = ttk.Label(window, text="Ширина листа в мм. : ")
label1.pack(anchor="center", padx=20, pady=10)
entry_width = ttk.Entry(window)
entry_width.pack(anchor="center", padx=20, pady=10)
width = entry_width.get()
int_width = int(width)
label2 = ttk.Label(window, text="Длинна листа в мм. : ")
label2.pack(anchor="center", padx=20, pady=10)
entry_height = ttk.Entry(window)
entry_height.pack(anchor="center", padx=20, pady=10)
height = entry_height.get()
int_height = int(height)
label3 = ttk.Label(window, text="Масса листа в граммах : ")
label3.pack(anchor="center", padx=20, pady=10)
entry_mass = ttk.Entry(window)
entry_mass.pack(anchor="center", padx=20, pady=10)
mass = entry_mass.get()
int_mass = int(mass)
label4 = ttk.Label(window, text="Количество листов в шт. : ")
label4.pack(anchor="center", padx=20, pady=10)
entry_sheets = ttk.Entry(window)
entry_sheets.pack(anchor="center", padx=20, pady=10)
sheet = entry_sheets.get()
int_sheets = int(sheet)
label5 = ttk.Label(window, text="ИТОГО")
label5.pack(anchor="center", padx=20, pady=10)
def calc_1():
answer = int_width * int_height * int_mass * int_sheets
label5.config(text=answer)
btn_calculated = ttk.Button(window, text="Рассчет", command=calc_1)
btn_calculated.pack(anchor="center", padx=20, pady=10)
btn_win1 = ttk.Button(text="Листы в киллограммы", command=new_window)
btn_win1.pack(anchor="center", padx=20, pady=10)
root.mainloop()