0

I'm a beginner to python programming. I want to print what text written in label when I click add button I tried I got the error was displayed

totall = tot.cget("text") AttributeError: 'NoneType' object has no attribute 'cget'

from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Inventory System using Python")
root.geometry("1000x500")


def show():
    totall = tot.cget("text")
    print(totall)


tot = Label(root, text="sss",font="arial 22 bold").place(x=650, y=10)
Button(root, text="Add",command = show,height=3, width= 13).place(x=650, y=50)


root.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
tuts fun
  • 117
  • 1
  • 11

1 Answers1

3

The problem is you call place inline you define tot as Label that method returns None, so you can not get the text from a NoneType.

Split place method on another line and it will work.

tot = Label(root, text="sss",font="arial 22 bold")
tot.place(x=650, y=10)
Just for fun
  • 4,102
  • 1
  • 5
  • 11