L
L
leon -----2021-06-17 18:55:12
Python
leon -----, 2021-06-17 18:55:12

Throws Tkinter error: AttributeError?

I wrote a program that calculates change. But when I click on the button it throws an error:
col1 = float(coldenent.get())
AttributeError: 'NoneType' object has no attribute 'get'

Here is the code:

from tkinter import *

def chet():
  col1 = float(coldenent.get())
  col2 = float(coldenent1.get())
  col1 - col2
  colchet = Label(root,text=col1).place(relx=0.44,rely=0.6)

root = Tk()
root.title("LoGic")
root.geometry('400x500')

colden = Label(root,text="Кол-во денег").place(relx=0,rely=0)
colden1 = Label(root,text="|   Стоимость   |").place(relx=0.2,rely=0)
col = Button(root,text="Сдача:",command=chet).place(relx=0.44,rely=0)

coldenent = Entry(root,width=12).place(relx=0.01,rely=0.06)
coldenent1 = Entry(root,width=12).place(relx=0.22,rely=0.06)

root.mainloop()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-06-17
@leon1000

This shit code will crash with a ValueError if the user enters a string...
Your problem is that you are writing to a variable not an object of the Entry type, but None which is returned by the place() function. Better do it on a separate line

D
Daniil Shevkunov, 2021-06-17
@danila763

Coldenet variable does not exist (in function chet)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question