我已经得到了一切在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