python object is NoneType even after declaring as global: ttk textbox

emagnun soorajspadmanabhan at gmail.com
Mon Jun 15 04:47:44 EDT 2020


I have a very simple script that retrieves the value from a text box upon click of a checkButton. But in click event, I'm receiving text box object as NoneType even after setting it as global. Pls help.

Output: !!ERROR!! Tag is None

########### Source Code ###########
from tkinter import *
from tkinter import ttk
import os

def submitData():
    global tag
    global tagBox
    if (tagBox is not None):
        tag = tagBox.get("1.0","end-1c")
        print ("!!SUCESS!! tag -->", tag)
    else:
        print ("!!ERROR!! Tag is None")

gui = Tk()
gui.title("GUI")
gui.geometry('250x300')

tag = "NA"
tagBoxLabel = Label(gui, text = "Tag: ").grid(column=0, row=5, pady=30, sticky="EN")
tagBox = Text(gui, height=1, width=20).grid(column=1, row=5, pady=30, sticky="WN")

submitButton = ttk.Button(gui, text="Submit", command=lambda: submitData()).grid(column=1, row=7)
gui.mainloop()


More information about the Python-list mailing list