我在使用Python的Tkinter按钮时遇到麻烦

时间:2019-04-29 17:09:07

标签: python python-3.x tkinter

我已经编写了该程序,我需要Tkinter按钮的帮助,该按钮不会显示以将用户的输入保存在用户回答问题的页面上。出现另一页,但我无法保存任何用户输入

import tkinter as tk
def amgtotal(tire_cost,oil_cost,insur_cost,window10):
    #open a new page
    window17 = tk.Tk()

    #label for the page
    amgpage = tk.Label(window17,text="Mercedes Benz AMG E63s Maintenance Total").pack(anchor="center")

    #total cost for tires
    amgpage = tk.Label(window17, text="Tire Cost: $"+ str(tire_cost.get()) )
    amgpage.pack(anchor='w')

    #total cost for oil change
    amgpage = tk.Label(window17, text="Oil Change Cost: $"+ str(oil_cost.get()))
    amgpage.pack(anchor='w')

    #total cost for Insurance
    amgpage = tk.Label(window17, text="Insurance Change Cost: $"+ str(insur_cost.get()))
    amgpage.pack(anchor='w')

    #total cost calc
    p= (tire_cost.get() +oil_cost.get()+insur_cost.get())

    #total cost
    amgpage = tk.Label(window17, text="Total Cost: $"+str(p))
    amgpage.pack(anchor='w')

    #size for window
    window17.geometry("400x400")

    #window title   
    window17.title("Mercedes Benz AMG E63s Maintenance Total")

    window17.mainloop()
#make a new window
window10 = tk.Tk()
#lable what the page is
amgpage = tk.Label(window10, text="Mercedes Benz AMG E63s Maintenance Calculator")
amgpage.pack(anchor='n')

#ask the user how many tires are needed
amgpage2 = tk.Label(window10, text="How many new tires do you need?")
amgpage2.pack(anchor='w')

#make gr1 a intger varible
gr1=tk.IntVar()

#double the value
tire_cost = tk.DoubleVar()

#make gr1 a intger varible
gr2=tk.IntVar()

#double the value
oil_cost = tk.DoubleVar()

#make gr1 a intger varible
gr3=tk.IntVar()

#double the value
insur_cost = tk.DoubleVar()


#radio button on how many tires are needed
for i in range(5):
    tire = tk.Radiobutton(window10, text=i, variable = gr1, value=i)
    tire['command'] = lambda i=i : tire_cost.set( 227.97*i )
    tire.pack(anchor='w')

#making space between questions 
amgpage = tk.Label(window10, text="")
amgpage.pack(anchor='w')

#asking the user if they want an oil change     
amgpage = tk.Label(window10, text="Do you need a oil change for your car?")
amgpage.pack(anchor='w')


#raidobuttions if they want a oil change or not
oil = tk.Radiobutton(window10, text="Yes", variable = gr2, value=1)
oil['command'] = lambda i=i : oil_cost.set( 261.00*1 )
oil.pack(anchor='w')

oil = tk.Radiobutton(window10, text="No", variable = gr2, value=2)
oil['command'] = lambda i=i : oil_cost.set( 261.00*0 )
oil.pack(anchor='w')

#makeing space  
amgpage = tk.Label(window10, text="")
amgpage.pack(anchor='w')

#asking the user if they want to add insurance to see the total cost
amgpage = tk.Label(window10, text="Do want to add the cost of insurance for the whole year to the total?")
amgpage.pack(anchor='w')

#radiobuttons for insurance
insur = tk.Radiobutton(window10, text="Yes", variable = gr3, value=1)
insur['command'] = lambda i=i : insur_cost.set( 2652.00*1 )
insur.pack(anchor='w')

insur = tk.Radiobutton(window10, text="No", variable = gr3, value=2)
insur['command'] = lambda i=i : insur_cost.set( 2652.00*0 )
insur.pack(anchor='w')

#making space between questions     
amgpage = tk.Label(window10, text="")
amgpage.pack(anchor='w')

#Get the total cost for maintenace
amgpage = tk.Button(window10,text= "Get total cost", command = amgtotal(tire_cost,oil_cost,insur_cost,window10),fg = 'Green')
amgpage.pack(anchor='w')

#making space between questions             
amgpage = tk.Label(window10, text="")
amgpage.pack(anchor='w')

#size for window size
window10.geometry("700x400")

#window title       
window10.title("Mercedes Benz AMG E63s Maintenance Calculator")

#end of window10 loop
window10.mainloop()

我希望该按钮保存用户输入,然后在另一页上打印计算。 预先感谢

0 个答案:

没有答案