TKinter程序计算增值税返回“无法将序列乘以'float'类型的非整数

如标题所述,我正在尝试tkinter,而程序运行时返回“无法将序列乘以'float'类型的非整数'

#from tkinter import *
from tkinter import *

def parathiro():
    price = entry_1.get()
    vat = (price * 0.24)
    final_price = (price + vat)
    string_to_display = "Ο Φ.Π.Α. είναι" + final_price
    Label_2 = Label(my_window)
    Label_2["text"] = string_to_display
    label_2.grid(row=1, column=1)


my_window = Tk()

label_1 = Label (my_window, text="Εισαγωγή Τιμής. . .:")
entry_1 = Entry (my_window)
button_1 = Button (my_window, text="Υπολογισμός Τιμής", command=parathiro)

label_1.grid(row=0, column=0)
entry_1.grid(row=0, column=1)
button_1.grid(row=1, column=0)

my_window.mainloop()
评论
  • 加载中…
    加载中… 回复

    This is a type issue. entry_1.get() return string, you need to convert it to float.

    Also, when creating string_to_display, you need to convert final_price to string.

    from tkinter import *
    
    def parathiro():
        price = float(entry_1.get())
        vat = (price * 0.24)
        final_price = (price + vat)
        string_to_display = "Ο Φ.Π.Α. είναι" + str(final_price)
        Label_2 = Label(my_window)
        Label_2["text"] = string_to_display
        Label_2.grid(row=1, column=1)
    
    
    my_window = Tk()
    
    label_1 = Label (my_window, text="Εισαγωγή Τιμής. . .:")
    entry_1 = Entry (my_window)
    button_1 = Button (my_window, text="Υπολογισμός Τιμής", command=parathiro)
    
    label_1.grid(row=0, column=0)
    entry_1.grid(row=0, column=1)
    button_1.grid(row=1, column=0)
    
    my_window.mainloop()