Tkinter on PyCharm not working

已完成

Hello, I have problem with tkinter on pycharm. 

import tkinter
canvas = tkinter.Canvas()
canvas.pack()



Traceback (most recent call last):
File "xxx", line 1, in <module>
import tkinter
File "xxx", line 2, in <module>
canvas = tkinter.Canvas()
AttributeError: partially initialized module 'tkinter' has no attribute 'Canvas' (most likely due to a circular import)

0

Where does it navigate if you Ctrl+Click (or Ctrl+B) tkinter in the code?

Does it happen in a new project with a new virtual environment?

1

Do you have modules named tkinter in your project?

They may conflict with the tkinter package.

0

Does the same error appear if you run it from the system terminal with the same interpreter?

0

I have Windows 10, Pycharm 2019.3.4, Python 3.8.2,

I'm going to "cmd" to make a new folder using "virtualenv graphics ". I'll activate it.

I'll open Pycharm, find my folder there. I will create a new Python file. I will write:

import tkinter
canvas = tkinter.Canvas()
canvas.pack()

At the top right click on "add configuration" give "+" and select "Python" click on "Script path" and select the file. I'll give "ok" and run.
starts:

Traceback (most recent call last):
  File "C:/Users/tomas/Desktop/graphics/tkinter.py", line 1, in <module>
    import tkinter
  File "C:\Users\tomas\Desktop\graphics\tkinter.py", line 3, in <module>
    canvas = tkinter.Canvas()
AttributeError: partially initialized module 'tkinter' has no attribute 'Canvas' (most likely due to a circular import)

0

So your file is called tkinter.py

Could you rename it and see if it helps?

0

It work. Thanks you so much.

0

请先登录再写评论。