Having trouble with Tkinter in PyCharm edu

Answered

I've had trouble importing the Tkinter library. When I do it on IDLE, it works fine, and the Tkinter window pops up. However, using the same code, i tried it on PyCharm, and nothing happens. All i see is  "Process finished with Exit code 0"

Here is my code:

from tkinter import *
window = Tk()

As you can see, I'm trying to get a blank Tkinter window to pop up.

I'd like to know if it's something wrong with my code, or if Tkinter simply doesn't work on PyCharm.

Thanks!

2
6 comments
Avatar
Permanently deleted user

Sorry for the bad explanation, I am a beginner in python.

1

Hello! You will get the same result if you run your script with the same interpreter in OS Terminal (command line) so the problem is not PyCharm-related.

Please see https://stackoverflow.com/questions/8683217/when-do-i-need-to-call-mainloop-in-a-tkinter-application.

 

0

I got a problem with pycharm and tkinter pycharm can not import the library is just can not find the library and the library is inside python 3.7 installation windows, please I need help I try change python folder I try everything and nothing.

1

Does PyCharm mark tkinter import as unresolved or are there any other errors? Could you provide a code sample?

0
Avatar
Permanently deleted user

#Delete python2 in Ubuntu terminal first. Than ilstall a python3.

sudo su

apt-get remove python-tk -y

apt-get remove python -y

apt-get install python3 -y

apt-get install python3-tk -y

reboot

#Check is there a python3 interpreter select in the IDE settings 'Project'->'Project Interpreter'.

#Select folfer '/usr/bin/python3' manually.

#

#test on the IDE

from tkinter import *
root = Tk()
root.mainloop()

#Now you have to see a window.

#You're welcome!

0

I have similar problem on

PyCharm Community Edition 2017.2.3
Build #PC-172.3968.37, built on September 1, 2017
JRE: 1.8.0_152-release-915-b11 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

It gets same 'resolve' issue then i'm trying import it from IDE:

import tkinter as tk

top = tk.Tk()
<my windows ID>\AppData\Local\Programs\Python\Python37-32\python.exe <my windows ID>/PycharmProjects/tkinter/tkinter.py
Traceback (most recent call last):
File "<my windows ID>/PycharmProjects/tkinter/tkinter.py", line 1, in <module>
import tkinter as tk
File "<my windows ID>\PycharmProjects\tkinter\tkinter.py", line 4, in <module>
  top = tk.Tk()
AttributeError: module 'tkinter' has no attribute 'Tk'

But if I try to import tkinter from pycharm console it works fine 

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
import tkinter as tk

tk.__doc__
'Wrapper functions for Tcl/Tk...

How this magic works? 

0

Please sign in to leave a comment.