git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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()