Tkinter is not a module in Ubuntu 20.04
Question:
I was on my computer and I was trying to code some tkinter code but when I put the starters in Pycharm, there was an error saying that Tkinter is not a module and then I tested it as tkinter and it was also not found. Can someone please help me get this sorted out as I really want to do some coding and this is slowing it down.
Thanks!
Answers:
Is it installed on your OS? You can try sudo apt install python3-tk
or sudo apt install python-tk
.
You could also try installing it via pip: pip install python-tk
For Python 3, beyond installing with
sudo apt-get install python3-tk
the following will help to get it to work:
instead of
from Tkinter import *
use from tkinter import *
or generic suitable for both Python2 and Python 3
import sys
if sys.version_info[0] == 3:
from tkinter import *
else:
from Tkinter import *
Similarly:
instead of import Tkinter as tk
use import tkinter as tk
or generic suitable for both Python2 and Python 3
import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk
I was on my computer and I was trying to code some tkinter code but when I put the starters in Pycharm, there was an error saying that Tkinter is not a module and then I tested it as tkinter and it was also not found. Can someone please help me get this sorted out as I really want to do some coding and this is slowing it down.
Thanks!
Is it installed on your OS? You can try sudo apt install python3-tk
or sudo apt install python-tk
.
You could also try installing it via pip: pip install python-tk
For Python 3, beyond installing with
sudo apt-get install python3-tk
the following will help to get it to work:
instead of
from Tkinter import *
use from tkinter import *
or generic suitable for both Python2 and Python 3
import sys
if sys.version_info[0] == 3:
from tkinter import *
else:
from Tkinter import *
Similarly:
instead of import Tkinter as tk
use import tkinter as tk
or generic suitable for both Python2 and Python 3
import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk