-7
import tkinter as Tk
from tkinter import ttk
import math as m
win=Tk.Tk()
win.title("Propeller Inputs")

inputFrame=ttk.LabelFrame(win,text="Input")
inputFrame.grid(column=0,row=0)

inputlabel=('Water','Lubrication','Power(KW)','Engine speed(rpm)','Gearbox ratio','Shaft strength(N/mm^2)','Bolt strength(N/mm^2)','Number of bolts','PCD of bolts(mm)')
for a in range (0,9):
    ttk.Label(inputFrame,text=inputlabel[a]).grid(column=0, row=a, pady=5)

#Adding a Combobox
water1=Tk.StringVar()
water1=ttk.Combobox(inputFrame, width=20)
water1['values']=("Sea", "River")
water1.grid(column=1, row=0)
water1.current(0)

lub1=Tk.StringVar()
lub1=ttk.Combobox(inputFrame, width=20)
lub1['values']=("Water", "Oil")
lub1.grid(column=1, row=1)
lub1.current(0)

#Adding a Textbox
P1=Tk.StringVar()
P1=ttk.Entry(inputFrame, width=20)
P1.grid(column=1, row=2)

en1=Tk.StringVar()
en1=ttk.Entry(inputFrame, width=20)
en1.grid(column=1, row=3)

gb1=Tk.StringVar()
gb1=ttk.Entry(inputFrame, width=20)
gb1.grid(column=1, row=4)

T1=Tk.StringVar()
T1=ttk.Entry(inputFrame, width=20)
T1.grid(column=1, row=5)

Tb1=Tk.StringVar()
Tb1=ttk.Entry(inputFrame, width=20)
Tb1.grid(column=1, row=6)

i1=Tk.StringVar()
i1=ttk.Entry(inputFrame, width=20)
i1.grid(column=1, row=7)

D1=Tk.StringVar()
D1=ttk.Entry(inputFrame, width=20)
D1.grid(column=1, row=8)




def calculate():   
    P=float(P1.get())

    en=float(en1.get())
    gb=float(gb1.get())
    T=float(T1.get())
#    Tb=float(Tb1.get())
#    i=float(i1.get())
#    D=float(D1.get())
    k2=1.10
    n=m.ceil(en/gb)


    if "Water" in (lub1.get()):
        #print("Water lubricated")
        k1=1.29
    else:
        #print("Oil lubricated")
        k1=1.26
    #print (k1)


    #tailshaft dia, intermediate shaft dia 
    if "Sea" in (water1.get()):
        dp=m.ceil(100*k1*((560*P)/(n*(T+160)))**0.33)
        d=m.ceil(100*k2*((560*P)/(n*(T+160)))**0.33)

    else:
        dp=m.ceil(103.5*k1*((410*P)/(n*(T+160)))**0.33)
        d=m.ceil(103.5*k2*((410*P)/(n*(T+160)))**0.33)

#    return (dp,d)


    update(dp,d)    


def update(dp,d):

    T=float(T1.get())
    Tb=float(Tb1.get())
    i=float(i1.get())
    D=float(D1.get())

    #bolt dia
    if "Sea" in (water1.get()):
        db=m.ceil(0.65*(((d**3.0)*(T+160))/(i*D*Tb))**0.5)
    else:
        db=m.ceil(((0.427*(d**3.0)*(T+155))/(i*D*Tb))**0.5)

    #liner thickness
    t=m.ceil((168+dp)/28) 

    #bush length
    if "Water" in (lub1.get()):
         l=m.ceil(4*dp) 

    else:
         l=m.ceil(2*dp) 

    #c/s area of key
    Ak=m.ceil((d**3)/(2.6*d))
    print(dp,d,db,Ak,l,t)
    #Output  frame
    outputFrame=ttk.LabelFrame(win,text="Output")
    outputFrame.grid(column=2,row=0)

    outputlabel=("Diameter of Tailshaft (mm)=","Diameter of Intermediate shaft (mm) =","Diameter of bolt (mm) =","Thickness of liner (mm) =","Sternbush bearing length (mm) =","Cross-sectional Area of keyway (mm^2) =")
    for a in range (0,6):
        ttk.Label(outputFrame,text=outputlabel[a]).grid(column=0, row=a, padx=20)

    output=(dp,d,db,t,l,Ak)
    for a in range (0,6):
        ttk.Label(outputFrame,text=output[a]).grid(column=1, row=a, padx=20)

    #Adding a button
    enter1=ttk.Button(outputFrame, text="Change values", command=change)
    enter1.grid(column=1, row=10)



def change():

    #Customer Changes Frame
    updateFrame=ttk.LabelFrame(win,text="Changes")
    updateFrame.grid(column=0,row=12)

    changelabel=("Diameter of Tailshaft (mm)","Diameter of Intermediate shaft (mm)")
    for b in range (0,2):
        ttk.Label(updateFrame,text=changelabel[b]).grid(column=0, row=b, pady=5)

    dp=Tk.StringVar()
    dp=ttk.Entry(updateFrame, width=20)
    dp.grid(column=1, row=0)

    d=Tk.StringVar()
    d=ttk.Entry(updateFrame, width=20)
    d.grid(column=1, row=1)
    dp1=dp.get()

    d1=d.get()


    #Adding a button
    enter2=ttk.Button(updateFrame, text="Update", command=lambda:update(dp1,d1))
    enter2.grid(column=1, row=2, pady=10)

    return(dp,d)




#Adding a button
enter=ttk.Button(inputFrame, text="Calculate", command=calculate)
enter.grid(column=1, row=10, pady=5)



win.mainloop()

error:

1080.0 921.0 1122 326247 4320 45
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Mayur\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "C:/Users/Mayur/Desktop/Program using function calls 01 (single error).py", line 171, in <lambda>
    enter2=ttk.Button(updateFrame, text="Update", command=lambda:update(dp1,d1))
  File "C:/Users/Mayur/Desktop/Program using function calls 01 (single error).py", line 113, in update
    db=m.ceil(0.65*(((d**3.0)*(T+160))/(i*D*Tb))**0.5)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'float'

i'm not getting where in code string multiplied with float.
Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
  • check update method in the code you posted. You will find the last line of the error in your code – Arpit Solanki Jan 12 '18 at 15:02
  • Please post a __minimal__ complete verifiable example. – bruno desthuilliers Jan 12 '18 at 15:04
  • please elaborate it.@ArpitSolanki – Mayur Shevate Jan 12 '18 at 15:05
  • _"i'm not getting where in code string multiplied with float."_ - the error message is telling you _precisely_ where you're doing this: `File "C:/Users/Mayur/Desktop/Program using function calls 01 (single error).py", line 113, in update`. What this means is that you are assuming that some of the values in that calculation are numbers, but they are strings. You need to do some debugging to verify that the values are what you think they are. – Bryan Oakley Jan 12 '18 at 15:40
  • Please read [How to ask](https://stackoverflow.com/help/how-to-ask). Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Please read [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting). – buhtz Jan 13 '18 at 05:03

1 Answers1

1

The error states that the problem is with ** or pow(), and with the line db=m.ceil(0.65*(((d**3.0)*(T+160))/(i*D*Tb))**0.5).

So the problem must lie with either of the ** operators in this statement.
It's hard to see how ((d**3.0)*(T+160))/(i*D*Tb)) could yield a string, so the error must lie here: d**3.0; d must be a string

Your lambda is lambda:update(dp1,d1), and, earlier you have d1=d.get(). get() will return a string, so you are passing a string as a second argument to update(), which causes your error.

Changing d1=d.get() to d1=int(d.get()) or d1=float(d.get()) (with some error-checking for a non-numeric case) should fix it.

SiHa
  • 7,830
  • 13
  • 34
  • 43