2017-05-02 27 views
-1

我已經得到了一切在gui中顯示,但現在我無法正確顯示稅轉換。Python Tkinter房產稅圖形用戶界面

這是我的代碼後,通過一些更多。我現在爲每個標籤創建了兩個stringvar對象。但是,似乎無法將房產稅轉換爲浮動稅。

對於每100美元的評估價值,房產稅應爲0.75美元。

因此,如果你輸入250000的屬性值,那就需要返回15萬的評估值和1125

import tkinter 


def main(): 
    my_gui = PropertyTaxGUI() 

class PropertyTaxGUI(): 

    def __init__(self): 
     self.main_window = tkinter.Tk() 

     self.top_frame = tkinter.Frame() 
     self.mid_frame = tkinter.Frame() 
     self.third_frame = tkinter.Frame() 
     self.bottom_frame = tkinter.Frame() 

     #create widgets for the top frame 
     self.prompt_label = tkinter.Label(self.top_frame, 
              text='Enter the property value: $') 
     self.prop_value = tkinter.Entry(self.top_frame, 
             width=10) 

     #pack the top frame's widgets 
     self.prompt_label.pack(side='left') 
     self.prop_value.pack(side='left') 

     #create widgets for the middle frame 
     self.assess_val = tkinter.Label(self.mid_frame, 
             text='Assessment Value: $') 

     #need a stringvar object to associate with an output label 
     self.value = tkinter.StringVar() 

     #create a label and associate it with the stringvar object 
     self.assess_label = tkinter.Label(self.mid_frame, 
              textvariable=self.value) 

     #pack the middle frame's widgets 
     self.assess_val.pack(side='left') 
     self.assess_label.pack(side='left') 

     #create the widgets for the third frame 
     self.prop_tax = tkinter.Label(self.third_frame, 
             text='Property Tax: $') 

     #need a stringvar object to associate witih second output label 
     self.value2 = tkinter.StringVar() 

     #create a label and associate it with the stringvar object 
     self.prop_tax_val = tkinter.Label(self.third_frame, 
              textvariable=self.value2) 

     #pack the third frame's widgets 
     self.prop_tax.pack(side='left') 
     self.prop_tax_val.pack(side='left') 

     #create the button widgets for the bottom frame 
     self.calc_button = tkinter.Button(self.bottom_frame, 
              text='Calculate', 
              command=self.calc_button_event) 
     self.quit_button = tkinter.Button(self.bottom_frame, 
              text='Quit', 
              command=self.main_window.destroy) 

     #pack the buttons 
     self.calc_button.pack(side='left') 
     self.quit_button.pack(side='left') 

     #pack the frames 
     self.top_frame.pack() 
     self.mid_frame.pack() 
     self.third_frame.pack() 
     self.bottom_frame.pack() 

     #enter the tkinter main loop 
     tkinter.mainloop() 

    def calc_button_event(self): 
     self.calculate() 
     self.taxCalc() 


    def calculate(self): 
     propVal = float(self.prop_value.get()) 

     assessVal = propVal*0.6 

     self.value.set(assessVal) 

    def taxCalc(self): 

     assessVal = float(self.value2.get()) 

     assessTax = assessVal*0.0075 

     self.value2.set(assessTax) 



main() 
+0

我相信你需要添加tkinter.Canvas()的高度和寬度尺寸。你現在擁有的是有效的,但不在畫布內。 – Ajax1234

+0

我現在編輯並提出了另一個問題。你能再看看我的代碼嗎? – Classicalclown

+0

作業:將您的標題轉換爲一個圓形的問句,我會將我的downvote更改爲up。 – peterh

回答

0

物業稅值我認爲你需要做的是有什麼只有一個函數計算總財產稅。您現在使用兩種方法,其中只有一種似乎被調用。試試這個代碼:

import tkinter 

class PropertyTaxGUI(): 

    def __init__(self): 
     self.main_window = tkinter.Tk() 

     self.top_frame = tkinter.Frame() 
     self.mid_frame = tkinter.Frame() 
     self.third_frame = tkinter.Frame() 
     self.bottom_frame = tkinter.Frame() 

     #create widgets for the top frame 
     self.prompt_label = tkinter.Label(self.top_frame, 
             text='Enter the property value: $') 
     self.prop_value = tkinter.Entry(self.top_frame, 
            width=10) 
     #pack the top frame's widgets 
     self.prompt_label.pack(side='left') 
     self.prop_value.pack(side='left') 

     #create widgets for the middle frame 
     self.assess_val = tkinter.Label(self.mid_frame, 
            text='Assessment Value: $') 

     #need a stringvar object to associate with an output label 
     self.value = tkinter.StringVar() 

     #create a label and associate it with the stringvar object 
     self.assess_label = tkinter.Label(self.mid_frame, 
             textvariable=self.value) 

     #pack the middle frame's widgets 
     self.assess_val.pack(side='left') 
     self.assess_label.pack(side='left') 

     #create the widgets for the third frame 
     self.prop_tax = tkinter.Label(self.third_frame, 
            text='Property Tax: $') 
     self.prop_tax_val = tkinter.Label(self.third_frame, 
             textvariable=self.value) 

     #pack the third frame's widgets 
     self.prop_tax.pack(side='left') 
     self.prop_tax_val.pack(side='left') 

     #create the button widgets for the bottom frame 
     self.calc_button = tkinter.Button(self.bottom_frame, 
             text='Calculate', 
             command=self.calculate) 
     self.quit_button = tkinter.Button(self.bottom_frame, 
             text='Quit', 
             command=self.main_window.destroy) 

     #pack the buttons 
     self.calc_button.pack(side='left') 
     self.quit_button.pack(side='left') 

     #pack the frames 
     self.top_frame.pack() 
     self.mid_frame.pack() 
     self.third_frame.pack() 
     self.bottom_frame.pack() 

     #enter the tkinter main loop 
     tkinter.mainloop() 

    def calculate(self): 
     self.propVal = float(self.prop_value.get()) 

     self.assessVal = self.propVal*0.6 

     self.property_tax = (self.propVal//100) * 0.74 
     self.value.set(self.property_tax+self.assessVal) 



#create an instance of the class 
my_gui = PropertyTaxGUI() 
+0

當物業稅根據評估值計算時,仍然給出相同的輸出。因此,評估價值爲房產價值的60%,評估價值爲每100美元的房產稅爲0.75。你的代碼給出.75的財產價值,並將其應用於評估價值和財產稅價值,使他們相同 – Classicalclown

+0

我想我理解這個問題好一點。請看我上次編輯的calculate()。 – Ajax1234

+0

不,它仍然在做同樣的事情。基本上,如果你輸入250000的房產價值,它需要返回評估價值150000和財產稅1125。你提供的東西給予了同樣的東西,用於propval和proptax – Classicalclown