-2

I want to rotate an image but I can't even open it. The answer I found does not work for me. I tried doing import PIL.Image but that doesn't work either. Any answers would be very helpful

from tkinter import *
from time import *
from math import *
from random import * 
from PIL import *



imageCar = Image.open("C:\\Users\\Antonio\\Desktop\\Python Programs\\GameFinal\\car.png")
Tontonio3
  • 11
  • 1

1 Answers1

-1

Welcome to StackOverflow!

It's considered bad practice to use * when importing from a package, exactly because it just dumps everything from that package into your code. If two different packages have something with the same name (like in your code tkinter.Image and PIL.Image), you get some strange errors.

It's unfortunate that the documentation for tkinter uses from tkinter import * as an example.

What you want is to selectively import what you need:

# Only import what you need. When imported like this, you
# use its name directly
from tkinter import TK
from tkinter import ttk
root = Tk()

If I'm calling an imported function just a couple time throughout my code, I usually import it like so as to not pollute my namespace:

import tkinter
from tkinter import ttk

# Prefix it with the package name you used to import
root = tkinter.Tk()

A pretty good tutorial on importing is

https://www.digitalocean.com/community/tutorials/how-to-import-modules-in-python-3

Cheers!

Leonardo
  • 1,533
  • 17
  • 28
  • I'd like to understand why was this answer downvoted. Doesn't it resolve the OP problem? It is unclear, or incomplete? A little feedback would be nice you know... – Leonardo Jun 27 '22 at 06:45