我已經得到了一切在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()
我相信你需要添加tkinter.Canvas()的高度和寬度尺寸。你現在擁有的是有效的,但不在畫布內。 – Ajax1234
我現在編輯並提出了另一個問題。你能再看看我的代碼嗎? – Classicalclown
作業:將您的標題轉換爲一個圓形的問句,我會將我的downvote更改爲up。 – peterh