-2

As the title says, i am experimenting with tkinter and while the program runs and it returns 'Can't multiply sequence by non-int of type '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()
  • 2
    Does this answer your question? [`cant-multiply-sequence-by-non-int-of-type-float`](https://stackoverflow.com/questions/3612378) – stovfl Feb 07 '20 at 10:22

1 Answers1

1

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()
Moshe perez
  • 1,626
  • 1
  • 8
  • 17