Feb-23-2020, 10:31 PM
Hi,
how can I interrupt the displaying of the result, as soon as I press the button? The question relates to the first page, as soon as you press the Welcome-button. Then you have to input the lenght, the height and the wide. After that you use the calculate-button and the result is depicted on the left side. But if I click the button again, the result is depicted again and so on...
I know the rest of the code is unfinished, but for the moment, I just want to solve this small problem...
how can I interrupt the displaying of the result, as soon as I press the button? The question relates to the first page, as soon as you press the Welcome-button. Then you have to input the lenght, the height and the wide. After that you use the calculate-button and the result is depicted on the left side. But if I click the button again, the result is depicted again and so on...
I know the rest of the code is unfinished, but for the moment, I just want to solve this small problem...
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib import style
import tkinter as tk
from tkinter import ttk
from tkinter import *
LARGE_FONT = ("Verdana", 12)
style.use("ggplot")
class reverberationTime(tk.Tk):
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "reverberation time")
tk.Tk.iconbitmap(self,"C:/Users/PC/Desktop/Icons/speaker.ico")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self,cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="reverberation time", font=LARGE_FONT)
label.pack(pady = 10, padx = 10)
button = ttk.Button(self, text="welcome!",
command=lambda: controller.show_frame(PageOne)).pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
NORMAL_FONT=("Arial",11)
title = tk.Label(self, text="Please enter the dimensions", font=LARGE_FONT)
title.pack(pady = 10, padx = 10)
frame = Frame(self)
frame.pack(pady=20)
lenght = StringVar()
wide = StringVar()
height = StringVar()
dimensions = Frame(frame)
dimensions.pack(side='left', pady=5)
entryfields = Frame(frame)
entryfields.pack(side='right', pady=5)
Label(dimensions, text="lenght:", font=NORMAL_FONT).pack(pady=3)
Label(dimensions, text="wide:", font=NORMAL_FONT).pack(pady=4)
Label(dimensions, text="height:", font=NORMAL_FONT).pack(pady=4)
#Label(eingaben, text="Fensteranteil:", font=NORMAL_FONT).pack(pady=4)
rl = Entry(entryfields, textvariable = lenght)
rl.pack(pady=6)
rw = Entry(entryfields, textvariable = wide)
rw .pack(pady=6)
rh = Entry(entryfields, textvariable = height)
rh.pack(pady=6)
#fa = Entry(entryfields)
#fa.pack(pady=6)
def calculate(carryOut):
try:
l = float(lenght.get())
b = float(wide.get())
h = float(height.get())
v = l*b*h
volume=Label(dimensions, text="volume: % .2f m³" % v).pack()
except ValueError:
tk.messagebox.showinfo('No valid input.','Please enter only numbers!',icon = 'warning')
#button3 = ttk.Button(self, text="berechnen",command=lambda: kalkulieren)
button3 = ttk.Button(self, text="calculate")
button3.pack()
button3.bind("<Button-1>", calculate)
button2 = ttk.Button(self, text="Page 2",
command=lambda: controller.show_frame(PageTwo))
button2.pack()
button1 = ttk.Button(self, text="Start Page",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page 2", font=LARGE_FONT)
label.pack(pady = 10, padx = 10)
button1 = ttk.Button(self, text="Start Page",
command=lambda: controller.show_frame(StartPage)).pack()
button2 = ttk.Button(self, text="Page 1",
command=lambda: controller.show_frame(PageOne)).pack()
class PageThree(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
app = reverberationTime()
app.mainloop()
