2017-06-21 12 views
0

私は、誰かが見積もりを請求する金額を計算するためのプログラムに取り組んでいますが、これまでのところ私はそれを働かせましたが、底にすべての値それは、各行にどのような価値があるかというラベルが付けられていないために不明瞭です。変数を表示しているラベルにテキストを追加する

ここにラベルを貼る方法を教えてください。

from tkinter import * 


app = Tk() 


woodType = {'Ash': 3562.39, 'Maple': 3554.01, 'Beech': 2661.32, 'Cherry': 
4887.15} 
choice_var = StringVar() 
dimensions = DoubleVar() 
employ = DoubleVar() 
length = DoubleVar() 
pay = DoubleVar() 


def math(): 
    D = dimensions.get() 
    choice = choice_var.get() 
    money = pay.get() 
    employee = employ.get() 
    time = length.get() 

    if choice == 'Ash': 
     woodPrice = woodType['Ash'] * D 
    if choice == 'Maple': 
     woodPrice = woodType['Maple'] * D 
    if choice == 'Beech': 
     woodPrice = woodType['Beech'] * D 
    if choice == 'Cherry': 
     woodPrice = woodType['Cherry'] * D 

    smallMaterials = 10/100* woodPrice 

    totalMaterialCost = woodPrice+smallMaterials 

    x = money*time 
    totalEmployeePay = x*employee 

    Price = totalMaterialCost+totalEmployeePay 

    GST = 20/100*totalMaterialCost 

    Overhead = 10/100 * Price 

    QuotePrice= Price+GST+Overhead 

    display(woodPrice, smallMaterials, totalMaterialCost, totalEmployeePay, Price,GST, Overhead,QuotePrice) 

def saving(): 
    print('waiting...') 

choice_var.set('Select wood type') 

Label(app, text='QUOTE CALCULATOR').grid(row=0, column=1, sticky=NSEW) 
OptionMenu(app, choice_var, 'Ash', 'Maple', 'Beech', 'Cherry').grid(row=1, column=1, sticky=NSEW) 

Label(app, text='Enter Dimensions of the wood (in cubic meters or gallons)').grid(row=2, column=1, sticky=NSEW) 
Entry(app, textvariable=dimensions).grid(row=3, column=1, sticky=NSEW) 

Label(app, text='Enter amount of employees on project').grid(row=4, column=1, sticky=NSEW) 
Entry(app, textvariable=employ).grid(row=5, column=1, sticky=NSEW) 

Label(app, text='Enter the estminated time being spent on project').grid(row=6, column=1, sticky=NSEW) 
Entry(app, textvariable=length).grid(row=7, column=1, sticky=NSEW) 

Label(app, text='Enter amount employees will be paided per hour').grid(row=8, column=1, sticky=NSEW) 
Entry(app, textvariable=pay).grid(row=9, column=1, sticky=NSEW) 

Button(app, text='Calulate', command=math).grid(row=10, column=1, sticky=NSEW) 
Button(app, text='Save', command=saving).grid(row=11, column=1, sticky=NSEW) 



def display(woodPrice, smallMaterials, totalMaterialCost, totalEmployeePay, Price,GST, Overhead,QuotePrice): 
    Label(app, text=woodPrice, relief="sunken").grid(row=12, column=1, sticky=NSEW) 
    Label(app, text=smallMaterials, relief="sunken").grid(row=13, column=1, sticky=NSEW) 
    Label(app, text=totalMaterialCost, relief="sunken").grid(row=14, column=1, sticky=NSEW) 
    Label(app, text=totalEmployeePay, relief="sunken").grid(row=15, column=1, sticky=NSEW) 
    Label(app, text=Price, relief="sunken").grid(row=16, column=1, sticky=NSEW) 
    Label(app, text=GST, relief="sunken").grid(row=17, column=1, sticky=NSEW) 
    Label(app, text=Overhead, relief="sunken").grid(row=18, column=1, sticky=NSEW) 
    Label(app, text=QuotePrice, relief="sunken").grid(row=19, column=1, sticky=NSEW) 

mainloop() 

答えて

0

各ラベルのtextに割り当てられた文字列を編集できます。

woodPriceText = "Wood Price: " + str(woodPrice) 
Label(app, text=woodPriceText, relief="sunken").grid(row=12, column=1, sticky=NSEW) 

または一時変数を使用して、直接割り当てない、

Label(app, text="Wood Price: " + str(woodPrice), relief="sunken").grid(row=12, column=1, sticky=NSEW) 
関連する問題