In the app I have been working on, I made it to have three windows.When I click the button on the first page to open a new window, it tells me a typeerror.I don’t understand as I made the function ‘next’ without any arguments. Here’s the code:
from tkinter import*
from ttkbootstrap.constants import*
import ttkbootstrap as tb
from PIL import Image,ImageTk
first=tb.Window(themename="cosmo")
first.geometry("1000x500+180+50")
Open an image file
img = Image.open("C:/Intel/UAM.jpg")
img_tk = ImageTk.PhotoImage(img)
Create a label and add the image to it
first.columnconfigure(0,weight=10)
first.columnconfigure(1,weight=1)
pic= tb.Label(first, image=img_tk)
pic.grid(row=0,column=0,rowspan=3,)
first_btn=tb.Button(first, text="Next", command=next, bootstyle="primary",width=10)
first_btn.grid(row=1,column=1,sticky=tb.W)
def next():
root=tb.Window(themename="cosmo")
root.title("UAM Simple Evaluator")
root.geometry("1000x500+180+50")
root.lift()
frame1=tb.Frame(root,bootstyle="light",borderwidth=0)
frame1.pack(pady=18,padx=18)
label1=tb.Label(frame1,text="Welcome to UAM Simple Evaluator!", font=("BrushScript", 24),bootstyle=("light,INVERSE"))
label1.pack(pady=10,padx=10)
paralabel2="""UAM Simple Evaluator utilizes the uniformly accelerated motion formulas
to return users with their desired physical quantities. In order to use it,
please input the numerical values of the known variables and
enter 'unknown' for the unknown variables below."""
frame2=tb.Frame(root,bootstyle="light")
frame2.pack(pady=5,padx=10)
label2=tb.Label(frame2,text=paralabel2,font=("ComicSans",18),wraplength=900,borderwidth=0,bootstyle=('light,INVERSE'),justify='center')
label2.pack(pady=10,padx=1,fill="both")
global frame3
frame3=tb.Frame(root,bootstyle='light')
frame3.pack(pady=5,padx=10)
frame3.columnconfigure(0,weight=1)
frame3.columnconfigure(1,weight=8)
frame3.columnconfigure(4,weight=1)
frame3.columnconfigure(5,weight=2)
S=tb.StringVar(frame3)
U=tb.StringVar(frame3)
V=tb.StringVar(frame3)
A=tb.StringVar(frame3)
T=tb.StringVar(frame3)
S_label=tb.Label(frame3, text="Displacement(m)", font=("Arial", 16))
S_entry=tb.Entry(frame3, font=("Arial",16),textvariable=S)
U_label=tb.Label(frame3, text="Initial Velocity(m/s)", font=("Arial", 16))
U_entry=tb.Entry(frame3, font=("Arial",16),textvariable=U)
V_label=tb.Label(frame3, text="Final Velocity(m/s)", font=("Arial", 16))
V_entry=tb.Entry(frame3, font=("Arial",16),textvariable=V)
A_label=tb.Label(frame3, text="Acceleration(m/s^2)", font=("Arial", 16))
A_entry=tb.Entry(frame3, font=("Arial",16),textvariable=A)
T_label=tb.Label(frame3, text="Time(s)", font=("Arial", 16))
T_entry=tb.Entry(frame3, font=("Arial",16),textvariable=T)
S_label.grid(row=0,column=0)
S_entry.grid(row=0,column=1,sticky=tb.W)
U_label.grid(row=1,column=0)
U_entry.grid(row=1,column=1,sticky=tb.W)
V_label.grid(row=2,column=0)
V_entry.grid(row=2,column=1,sticky=tb.W)
A_label.grid(row=3,column=0)
A_entry.grid(row=3,column=1,sticky=tb.W)
T_label.grid(row=4,column=0)
T_entry.grid(row=4,column=1,sticky=tb.W)
def UAM_Eval():
global S
global U
global V
global A
global T
if S.get()=='unknown' and A.get()=='unknown':
S1=((float(U.get())+float(V.get()))*float(T.get()))/2
A1=(float(V.get())-float(U.get()))/float(T.get())
S2=round(S1,2)
A2=round(A1,2)
print("The value of the distance is",(S2))
print("The value of the acceleration is",(A2))
elif S.get()=='unknown' and V.get()=='unknown':
S3=(float(U.get())*float(T.get()))+((float(A.get())*(float(T.get())**2))/2)
V1=float(U.get())+(float(A.get())*float(T.get()))
S4=round(S3,2)
V2=round(V1,2)
print("The value of the distance is",S4)
print("The value of the final velocity is",V2)
elif S.get()=='unknown' and U.get()=='unknown':
S5=(float(V.get())*float(T.get()))-(float(A.get())*(float(T.get())**2))/2
U1='float(V.get())-(float(A.get())*float(T.get()))'
S6=round(S5,2)
U2=round(U1,2)
print("The value of the distance is",S6)
print("The value of the initial velocity is",U2)
elif S.get()=='unknown' and T.get()=='unknown':
S7=((float(V.get())**2)-(float(U.get())**2))/(2*float(A.get()))
T1=(float(V.get())-float(U.get()))/float(A.get())
S8=round(S7,2)
T2=round(T1,2)
print("The value of the distance is",S8)
print("The value of the time is",T2)
elif U.get()=='unknown' and A.get()=='unknown':
U3=((2*float(S.get()))/float(T.get()))-float(V.get())
A3=(-2*(float(S.get())-(float(V.get())*float(T.get()))))/(float(T.get())**2)
U4=round(U2,2)
A4=round(A2,2)
print("The value of the initial velocity is",(U4))
print("The value of the acceleration is",(A4))
elif U.get()=='unknown' and V.get()=='unknown':
U5=(float(S.get())-((float(A.get())*(float(T.get())**2))/2))/float(T.get())
V3=(float(S.get())+((float(A.get())*(float(T.get())**2))/2))/float(T.get())
U6=round(U5,2)
V4=round(V3,2)
print("The value of the initial velocity is",U6)
print("The value of the final velocity is",V4)
elif U.get()=='unknown' and T.get()=='unknown':
U7=((float(V.get())**2)-(2*(float(A.get())*float(S.get()))))**(1/2)
U8=round(U7,2)
T3=(float(V.get())-float(U7))/float(A.get())
T4=round(T3,2)
print("The value of the initial velocity is",U8)
print("The value of the time is",T4)
elif V.get()=='unknown' and A.get()=='unknown':
V5=((2*float(S.get()))/float(T.get()))-float(U.get())
A5=((2*(float(S.get())-(float(U.get())*float(T.get())))))/(float(T.get())**2)
V6=round(V5,2)
A6=round(A5,2)
print("The value of the final velocity is",V6)
print("The value of the acceleration is",A6)
elif V.get()=='unknown' and T.get()=='unknown':
V7=((float(U.get())**2)+(2*float(A.get())*float(S.get())))**(1/2)
V8=round(V7,2)
T5=(float(V7)-float(U.get()))/float(A.get())
T6=round(eval(T5),2)
print("The value of the final velocity is",V8)
print("The value of the time is",T6)
elif A.get()=='unknown' and T.get()=='unknown':
A7=((float(V.get())**2)-(float(U.get())**2))/(2*float(S.get()))
T7=(2*float(S.get()))/(float(U.get())+float(V.get()))
A8=round(A7,2)
T8=round(T7,2)
print("The value of the acceleration is",A8)
print("The value of the time is",T8)
def result_printer():
results_window=tb.Window()
results_window.geometry("1000x500+180+50")
global result_label
result=UAM_Eval()
result_label.config(text=result)
result_frame=tb.Frame(results_window,bootstyle="light")
result_frame.pack(padx=15,pady=50)
result_label=tb.Label(result_frame,text="Here is the answer",font=("Arial",18))
result_label.pack(pady=50,padx=10)
results_window.mainloop()
Calc_btn=tb.Button(frame3, text="Calculate", command=UAM_Eval, width=20,bootstyle="primary")
result_btn=tb.Button(frame3,text="Next Page",command=result_printer,width=20,bootstyle="info")
result_label=tb.Label(root,text="Result will be shown here.")
result_label.pack(padx=10,pady=50)
Calc_btn.grid(row=5,column=1,rowspan=2,sticky=tb.N)
result_btn.grid(row=8,column=1,)
root.mainloop()
first.mainloop()`
What am I missing?
I would love some help.
New contributor
Mestawot Marimo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.