my function wont carry out for the button assigned. Im using visual studio code. For the
def myClick():
myLabel =Label(window, text …, command…
it wont occur. on visual studio code, the ‘myLabel’ greys out and has the error ‘is not accessedPylance’
# add response to input
def myClick():
myLabel = Label(window, text="Hello" + e.get() + "... ")
myLabel.pack
# create button
myButton = Button(window, text="next", command=myClick, fg="black")
myButton.pack()
4
Answers
I think its just that you are not calling
pack()
. When I fix that I see the label appear:I think you should pack myLabel inside the function, and add "()" at the end:
I see two problems with your code.
Firstly,
myLabel.pack()
is not aligned asmyLabel
.You have to call the
pack()
method in themyClick()
function.Secondly, dont forget to use the brackets for calling the pack() method on myLabel.
You can see a working example down here.
You are not calling the pack function. You wrote
myLabel.pack
without the brackets –()
– so Python does not recognize it as a function.Your code, improved:
Thanks for asking, keep up great work!