简体   繁体   中英

my code looks like good but doesn't work or show me result

when I run it doesn't show me the vat and sum in their labels I tried too much to solve that by more than one way but no result (I am new in programming).

this is my code:

 import tkinter as tk
 from tkinter import *

 root = tk.Tk()

 root.title("VatCalculator")
 root.geometry("300x200")
 root.configure(background ='grey')

 PriceLabel = Label(fg = "black" , bg ='grey',text = "the price").place(x =5 ,y =10 )
 price = tk.DoubleVar()
 PriceBox = tk.Entry(textvariable =price).place(x =10 ,y =30)

 VatLabel = Label(fg = "black" , bg ='grey', text = "the vat").place(x =5 , y=50)
 vat =tk.DoubleVar()
 VatBox =tk.Entry(textvariable =vat).place(x =10 , y=70)


 def button():
   price2 = float(price.get())
   vat2   = float(vat.get())
   getvat4 = price2 * vat2 / 100
   getvat.set(getvat4)
   getsum4 = price2 + getvat4
   getsum.set(getsum4)

 getvat = DoubleVar()
 getsum = DoubleVar()

 calculator = Button(height =1 , width =15 , text ="calculator" , command =button()).place(x =15 , 
 y =95)

 PVatbox = Label(fg = "black" , bg ='grey', text = "the vat is").place(x =10 , y =140)
 SVatBox = Label(bg = "white" , height =1 , width =20 , textvariable =getvat).place(x =80 , y =140)

 PSumbox = Label(fg = "black" , bg ='grey', text = "the sum is").place(x =10 , y =170)
 SSumbox = Label(bg ="white" , height =1 , width =20 , textvariable =getsum).place(x =80 , y =170)

 root.mainloop()

Change command=button() to command=button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM