2017-05-02 28 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