critic this please
Nick Perkins
nperkins7 at home.com
Thu Jun 21 16:12:49 EDT 2001
You probably want to write some functions with parameters to
avoid typing many functions with similar code.
It is also a good idea to try to separate the actual calculations
from the code that accesses and manipulates the GUI.]
Perhaps something like this will give you some ideas:
(untested)
slope_factor = {5: 13.0, # use 13.0, not just 13, to ensure accuracy
6: 13.42,
7: 13.89,
8: 20.0,
9: 15.0,
10: 15.62,
11: 16.28,
12: 16.67 }
# calcualte rafter length, and return the result
#
def rafter_length( run_feet, run_inches, slope_type):
factor = slope_factor[slope_type]
exact_run_feet = run_feet + (run_inches/12.0)
exact_rafter_feet = exact_run_feet * factor
return exact_rafter_feet
# get the input from the text fields, and display the answer
#
def display_rafter_length(slope_type)
a = float(Tkinter.Entry.get(feet))
b = float(Tkinter.Entry.get(inch))
Tkinter.Entry.delete(answer, 0, 20)
Tkinter.Entry.insert(answer, 0, rafter_length(a,b,slope_type))
def fig5():
display_rafter_length(5)
def fig6():
display_rafter_length(6)
..etc.
"NJM" <njm at rectec.net> wrote in message
news:tj4360hohgdk2c at corp.supernews.com...
> I've just wrote this small program that calculates the length of a rafter
> for you(I'm a carpenter), but I didn't write it "properly". I can't seem
to
> wrap my head around using classes. Does anyone have any input.
>
>
> import Tkinter
>
> def fig5():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*13)
>
> def fig6():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*13.42)
> def fig7():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*13.89)
>
> def fig8():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*14.42)
>
> def fig9():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*15)
>
> def fig10():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*15.62)
> def fig11():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*16.28)
> def fig12():
> a = float(Tkinter.Entry.get(feet))
> b = float(Tkinter.Entry.get(inch))
> Tkinter.Entry.delete(answer, 0, 20)
> Tkinter.Entry.insert(answer, 0, (b/12 + a)*16.97)
>
>
> root=Tkinter.Tk(className="/Rafter Lengths")
> frame=Tkinter.Frame(root, relief=Tkinter.RIDGE, borderwidth=2)
> frame.pack()
> label=Tkinter.Label(frame, text="This is a program that will calculate the
> rafter lengths for you")
> label.pack()
>
> frame2=Tkinter.Frame(root, borderwidth=0)
> frame2.pack()
>
> button=Tkinter.Button(frame2, text="'5-12'", command=fig5)
> button.pack(side=Tkinter.LEFT)
> button2=Tkinter.Button(frame2, text="'6-12'", command=fig6)
> button2.pack(side=Tkinter.LEFT)
> button3=Tkinter.Button(frame2, text="'7-12'", command=fig7)
> button3.pack(side=Tkinter.LEFT)
> button4=Tkinter.Button(frame2, text="'8-12'", command=fig8)
> button4.pack(side=Tkinter.LEFT)
> button5=Tkinter.Button(frame2, text="'9-12'", command=fig9)
> button5.pack(side=Tkinter.LEFT)
> button6=Tkinter.Button(frame2, text="'10-12'", command=fig10)
> button6.pack(side=Tkinter.LEFT)
> button7=Tkinter.Button(frame2, text="'11-12'", command=fig11)
> button7.pack(side=Tkinter.LEFT)
> button8=Tkinter.Button(frame2, text="'12-12'", command=fig12)
> button8.pack(side=Tkinter.LEFT)
> button9=Tkinter.Button(frame2, text="Quit", command=root.quit)
> button9.pack(side=Tkinter.LEFT)
>
> frame3=Tkinter.Frame(root, borderwidth=5)
> frame3.pack()
>
> labe=Tkinter.Label(frame3, text="Rafter Run to be calculated")
> labe.pack(side=Tkinter.LEFT)
>
> space=Tkinter.Label(frame3, width=5)
> space.pack(side=Tkinter.LEFT)
>
> label2=Tkinter.Label(frame3, text="Feet")
> label2.pack(side=Tkinter.LEFT)
> feet=Tkinter.Entry(frame3, width=5)
> feet.pack(side=Tkinter.LEFT)
>
> label3=Tkinter.Label(frame3, text="Inches", width=5)
> label3.pack(side=Tkinter.LEFT)
> inch=Tkinter.Entry(frame3, width=5)
> inch.pack(side=Tkinter.LEFT)
>
> frame4=Tkinter.Frame(root, relief=Tkinter.RIDGE, borderwidth=2)
> frame4.pack()
>
> label4=Tkinter.Label(frame4, text="Rafter Length in Inches")
> label4.pack(side=Tkinter.LEFT)
> answer=Tkinter.Entry(frame4)
> answer.pack(side=Tkinter.LEFT)
>
> frame5=Tkinter.Frame(root)
> frame5.pack()
>
> label5=Tkinter.Label(frame5, text="This length does not allow for \n the
> thickness of the ridge.")
> label5.pack()
>
> root.mainloop()
>
>
More information about the Python-list
mailing list