Python GUI“财产税”计划。运行程序时,似乎没有任何东西出现(即没有弹出单独的窗口)

时间:2018-06-06 02:54:14

标签: python python-3.x user-interface tkinter

这是我写的代码。它应该询问用户用户的房屋价值并返回评估价值和到期税。 我不确定我的计算机上的IDLE或我的程序是否存在问题。

该程序应该: 1.要求用户输入他们的房屋价值 2.给出评估值 3.包括至少2个按钮 4.工作(显然)

import tkinter

class PropertyTaxApp:
    def __init__(self):
        # Creates main Window
        self.main_window
        tkinter.mainloop()

        #Creates the four frames
        self.homevalue_frame = tkinter.Frame(self.main_window)
        self.assessmentvalue_frame = tkinter.Frame(self.main_window)
        self.propertytaxes_frame = tkinter.Frame(self.main_window)
        self.button_frame = tkinter.Frame(self.main_window)

        #Create and pack the widgets for the home value
        self.homevalue_label = tkinter.Label(self.homevalue_frame,
                                         text = "Enter your home's value here: ")
        self.homevalue_entry = tkinter.Entry(self.homevalue_frame,
                                         width=10)
        self.homevalue_label.pack(side="left")
        self.homevalue_entry.pack(side="left")

        #Create and pack the widgets for the assessment value
        self.result_label = tkinter.label(self.assessmentvalue_frame,
                                               text="Assessment Value: ")
        self.assessmentvalue_label = tkinter.label(self.assessmentvalue_frame,
                                               textvariable=self.assessmentvalue)
        self.result_label.pack(side="left")
        self.assessmentvalue_label.pack(side="left")

        #Create and pack the widgets for the property taxes
        self.result_label = tkinter.label(self.propertytaxes_frame,
                                               text="Property Taxes: ")
        self.propertytaxes_label = tkinter.label(self.propertytaxes_frame,
                                               textvariable=self.propertytaxes)
        self.result_label.pack(side="left")
        self.assessmentvalue_label.pack(side="left")

        #Create and pack the button widgets
        self.calculate_button = tkinter.Button(self.button_frame,
                                           text="Calculate",
                                           command=self.calc_info)
        self.quit_button = tkinter.Button(self.button_frame,
                                           text="Quit Program",
                                           command=self.main_window.destroy)
        self.calculate_button.pack(side="left")
        self.quit_button.pack(side="left")

        #Pack frames
        self.homevalue_frame.pack()
        self.assessmentvalue_frame.pack()
        self.propertytaxes_frame.pack()
        self.button_frame.pack()

        #Start the main loop
        tkinter.mainloop()

        #the calc_info method is used in the calculate_button widget
        def calc_info(self):
            #set constants
            self.assessmentvaluepct = 0.6
            self.propertytaxespct = 0.0075
            #get home value input by user
            self.homevalue = float(self.homevalue_entry.get())

            #calculate the assessment value and property taxes
            self.calculatedassessmentvalue=(self.assessmentvaluepct*self.homevalue)
            self.calculatedpropertytaxes=(self.propertytaxespct*self.homevalue)

            #update the propertytaxes_label widget
            self.propertytaxes.set(self.calculatedpropertytaxes)

            #update the assessmentvalue_label widget
            self.assessment.set(self.calculatedassessmentvalue)

        #Run the PropertyTaxApp Class
        property_tax_app = PropertyTaxApp()

提前非常感谢!

0 个答案:

没有答案