Label Is Not Defined












-1















What is wrong here please help. It's writing lbl1 is not defined. I defined it already is the order is wrong how can I repair it? Everyday im having a problem like this could you help mee???



import tkinter

window = tkinter.Tk()

window.title("Calculator 2")

window.geometry("400x400")




def func1():
lbl1 = tkinter.Label(window, text="1")
lbl1.pack()

def func2():
lbl2 = tkinter.Label(window, text="+")
lbl2.pack()
def func3():
lbl3 = tkinter.Label(window, text="2")
lbl3.pack()



btn1 = tkinter.Button(window, text="1", command=func1)
btn2 = tkinter.Button(window, text="+", command=func2)
btn3 = tkinter.Button(window, text="2", command=func3)
btn1.pack()
btn2.pack()
btn3.pack()

def funclst():
if lbl1 == "1" and lbl2 == "+" and lbl3 == "2":
rstt = tkinter.Label(window, text=(int(lbl1) + int(lbl3)))
rstt.pack()

lst = tkinter.Button(window, text="Calculate", command=funclst)
lst.pack()







window.mainloop()









share|improve this question

























  • Please include the complete error traceback, don't just cite approximately the error message.

    – Thierry Lathuille
    Nov 17 '18 at 12:11
















-1















What is wrong here please help. It's writing lbl1 is not defined. I defined it already is the order is wrong how can I repair it? Everyday im having a problem like this could you help mee???



import tkinter

window = tkinter.Tk()

window.title("Calculator 2")

window.geometry("400x400")




def func1():
lbl1 = tkinter.Label(window, text="1")
lbl1.pack()

def func2():
lbl2 = tkinter.Label(window, text="+")
lbl2.pack()
def func3():
lbl3 = tkinter.Label(window, text="2")
lbl3.pack()



btn1 = tkinter.Button(window, text="1", command=func1)
btn2 = tkinter.Button(window, text="+", command=func2)
btn3 = tkinter.Button(window, text="2", command=func3)
btn1.pack()
btn2.pack()
btn3.pack()

def funclst():
if lbl1 == "1" and lbl2 == "+" and lbl3 == "2":
rstt = tkinter.Label(window, text=(int(lbl1) + int(lbl3)))
rstt.pack()

lst = tkinter.Button(window, text="Calculate", command=funclst)
lst.pack()







window.mainloop()









share|improve this question

























  • Please include the complete error traceback, don't just cite approximately the error message.

    – Thierry Lathuille
    Nov 17 '18 at 12:11














-1












-1








-1








What is wrong here please help. It's writing lbl1 is not defined. I defined it already is the order is wrong how can I repair it? Everyday im having a problem like this could you help mee???



import tkinter

window = tkinter.Tk()

window.title("Calculator 2")

window.geometry("400x400")




def func1():
lbl1 = tkinter.Label(window, text="1")
lbl1.pack()

def func2():
lbl2 = tkinter.Label(window, text="+")
lbl2.pack()
def func3():
lbl3 = tkinter.Label(window, text="2")
lbl3.pack()



btn1 = tkinter.Button(window, text="1", command=func1)
btn2 = tkinter.Button(window, text="+", command=func2)
btn3 = tkinter.Button(window, text="2", command=func3)
btn1.pack()
btn2.pack()
btn3.pack()

def funclst():
if lbl1 == "1" and lbl2 == "+" and lbl3 == "2":
rstt = tkinter.Label(window, text=(int(lbl1) + int(lbl3)))
rstt.pack()

lst = tkinter.Button(window, text="Calculate", command=funclst)
lst.pack()







window.mainloop()









share|improve this question
















What is wrong here please help. It's writing lbl1 is not defined. I defined it already is the order is wrong how can I repair it? Everyday im having a problem like this could you help mee???



import tkinter

window = tkinter.Tk()

window.title("Calculator 2")

window.geometry("400x400")




def func1():
lbl1 = tkinter.Label(window, text="1")
lbl1.pack()

def func2():
lbl2 = tkinter.Label(window, text="+")
lbl2.pack()
def func3():
lbl3 = tkinter.Label(window, text="2")
lbl3.pack()



btn1 = tkinter.Button(window, text="1", command=func1)
btn2 = tkinter.Button(window, text="+", command=func2)
btn3 = tkinter.Button(window, text="2", command=func3)
btn1.pack()
btn2.pack()
btn3.pack()

def funclst():
if lbl1 == "1" and lbl2 == "+" and lbl3 == "2":
rstt = tkinter.Label(window, text=(int(lbl1) + int(lbl3)))
rstt.pack()

lst = tkinter.Button(window, text="Calculate", command=funclst)
lst.pack()







window.mainloop()






python tkinter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 12:25







Bati

















asked Nov 17 '18 at 12:09









BatiBati

12




12













  • Please include the complete error traceback, don't just cite approximately the error message.

    – Thierry Lathuille
    Nov 17 '18 at 12:11



















  • Please include the complete error traceback, don't just cite approximately the error message.

    – Thierry Lathuille
    Nov 17 '18 at 12:11

















Please include the complete error traceback, don't just cite approximately the error message.

– Thierry Lathuille
Nov 17 '18 at 12:11





Please include the complete error traceback, don't just cite approximately the error message.

– Thierry Lathuille
Nov 17 '18 at 12:11












1 Answer
1






active

oldest

votes


















0














You create the labels inside functions. When the function ends the names assigned to the labels are garbage collected. Later when you try to access the variables in the if statement they are not defined in the global scope.



Also; the if statements checks if lbl1 == "1" which will not work as lbl1 is the reference to the label and not to the text inside the label. The text can be accessed through lbl1['text'] or lbl1.cget("text")






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351109%2flabel-is-not-defined%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You create the labels inside functions. When the function ends the names assigned to the labels are garbage collected. Later when you try to access the variables in the if statement they are not defined in the global scope.



    Also; the if statements checks if lbl1 == "1" which will not work as lbl1 is the reference to the label and not to the text inside the label. The text can be accessed through lbl1['text'] or lbl1.cget("text")






    share|improve this answer




























      0














      You create the labels inside functions. When the function ends the names assigned to the labels are garbage collected. Later when you try to access the variables in the if statement they are not defined in the global scope.



      Also; the if statements checks if lbl1 == "1" which will not work as lbl1 is the reference to the label and not to the text inside the label. The text can be accessed through lbl1['text'] or lbl1.cget("text")






      share|improve this answer


























        0












        0








        0







        You create the labels inside functions. When the function ends the names assigned to the labels are garbage collected. Later when you try to access the variables in the if statement they are not defined in the global scope.



        Also; the if statements checks if lbl1 == "1" which will not work as lbl1 is the reference to the label and not to the text inside the label. The text can be accessed through lbl1['text'] or lbl1.cget("text")






        share|improve this answer













        You create the labels inside functions. When the function ends the names assigned to the labels are garbage collected. Later when you try to access the variables in the if statement they are not defined in the global scope.



        Also; the if statements checks if lbl1 == "1" which will not work as lbl1 is the reference to the label and not to the text inside the label. The text can be accessed through lbl1['text'] or lbl1.cget("text")







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 5:34









        figbeamfigbeam

        3,0851310




        3,0851310
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351109%2flabel-is-not-defined%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word