0

I use mac, learning python, using pycharm

code:

from tkinter import *
root = Tk()

root.mainloop()

result:

NameError: name 'Tk' is not defined

Then, I try to install python3-tk

I type sudo apt-get install python3-tk in terminal

result:

sudo: apt-get: command not found

Then, I try to update

I type sudo apt-get update

result:

sudo: apt-get: command not found

How can I fix the problem. Please help, thank you!!

hooon
  • 11
  • 1
  • It works on my machine. What OS/distribution are you using, and what version of python and TKinter? – OctaveL Nov 10 '20 at 10:06
  • 2
    Is your file name `tkinter` or something? If module was not found, it should have given some errors in the first line itself. – Delrius Euphoria Nov 10 '20 at 10:52
  • @OctaveL OS Catalina about the version of python, thats another problem I have installed version 3.8 but the default version is 2.7 just like pygame, I used many methods to install it to version 3.8 but it still be installed to 2.7 I select "inherit global site-package" in pycharm to fix that – hooon Nov 10 '20 at 10:57
  • @OctaveL and I just check tkinter version by "pip list" and I cant find the name of tkinter. Is that mean i haven't install it yet? – hooon Nov 10 '20 at 11:01
  • @CoolCloud no, file name is not tkinter. what do you mean by the first line. The first line of my python file? – hooon Nov 10 '20 at 11:04
  • First line was `from tkinter import *` they would give a `ModuleNotFoundError` if `tkinter` was not found, anyway have you tried `sudo dnf install python3-tkinter`. Take a look [here](https://stackoverflow.com/questions/25905540/importerror-no-module-named-tkinter) – Delrius Euphoria Nov 10 '20 at 11:10
  • @CoolCloud just try: result : sudo: dnf: command not found. – hooon Nov 10 '20 at 11:16
  • is something wrong with my setup of python? any modules or package must be installed before using python? – hooon Nov 10 '20 at 11:17
  • @HoOonLau You can't use `apt-get` or `dnf` because they're for Debian based Linux distributions and Red Hat based distros, respectively - you're on macOS. I don't use macOS but the issue here is definitely in your python setup or your tkinter installation, I can't really help much more. Try `brew install tcl-tk`, I suppose. – OctaveL Nov 10 '20 at 11:41
  • Why not just try the same code on python IDLE and try if it works? – Delrius Euphoria Nov 10 '20 at 11:42
  • 1
    Do this: `import tkinter; print(tkinter.__file__)`. It will tell you if you're importing the standard tkinter module or some file that has the same name. – Bryan Oakley Nov 10 '20 at 14:37

0 Answers0