2017-05-02 2 views
-1

나는 gui에 나타나기 위해 모든 것을 얻었지만 지금은 세금 환급을 올바르게받을 수 없습니다.파이썬 Tkinter 재산세 GUI

여기 좀 더 살펴본 후 제 코드입니다. 이제 각 레이블에 대해 두 개의 문자열 객체를 만들었습니다. 그러나 재산세를 부유세로 전환 할 수는 없습니다.

재산세는 평가 가치 $ 100마다 $ 0.75이어야합니다. 이 속성 값에 대한 250000을 입력한다면

따라서, 내가 당신이되어 무엇을해야하는지 생각 150000의 평가 값과 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가 위로 바뀝니다. – 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입니다. 귀하의 코드는 0.75의 재산 가치를 부여하고이를 평가 가치와 재산세 가치 모두에 적용합니다. – Classicalclown

+0

나는 조금 더 나은 점을 이해한다고 생각합니다. calculate()의 마지막 편집을 참조하십시오. – Ajax1234

+0

아니요, 여전히 똑같은 일을합니다. 기본적으로 속성 값으로 250000을 입력하면 평가 값은 150000, 재산세는 1125를 반환해야합니다. 당신이 제공 한 것은 propval과 proptax에 대해 동일한 것을 되돌려줍니다 – Classicalclown