0

Really simple code, but not working using tkinder in Python.

This code has been copied just as seen in a video tutorial, so I think it could be any config:

from tkinter import*

root=Tk()

miFrame=Frame(root, width=500, height=400)

miFrame=pack()

Label(miFrame, text="Hola alumnos de Python", fg="red", font=("Comic Sans 
MS", 18)).place(x=100, y=200)

root.mainloop()

The error:

Traceback (most recent call last): File "Prueba2.py", line 7, in miFrame=pack() NameError: name 'pack' is not defined

2 Answers 2

1

Replace miFrame=pack() with miFrame.pack()

Sign up to request clarification or add additional context in comments.

Comments

0

The row miFrame=pack() is an attempt to assign a symbol miFrame to a reference to some known function pack()

In a case, there is no such known to the python interpreter state, it threw an exception mentioned above.

However, the object miFrame, being a row above that assigned to a tkinter.Frame instance, there is an instance-method present - the .pack(), that can be called, instead of an attempt to straight re-assign the miFrame, right after it's instantiation:

miFrame = Frame( root, width  = 500,
                       height = 400
                       )
miFrame.pack() #_____________________ .pack() is a Frame-class instance-method

Label( miFrame, text = "Hola alumnos de Python",
                fg   = "red",
                font = ( "Comic Sans MS", 18 )
                ).place( x = 100,
                         y = 200
                         )

1 Comment

Thanks! That was the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.