Where is Tkapp located? - python

I'm working on creating an interface between tkinter and JSON. I need to look through the code of Tkapp to do so because I need to understand its attributes. Failing that, how can I import it?
from tkinter import _tkinter
from _tkinter import tkapp
Returns an ImportError

_tkinter is a C-based module. tkapp is defined in its source code which you can find here on GitHub.

Related

Importing stuff from tkinter Python

I am new to Python Programming.
I am using tkinter module to import stuff for graphical user interface.
I import everything from the tkinter module by typing the following statement:
from tkinter import *
Why do I still need to import some certain classes separately from the same module like simpledialog although we have imported everything using the above statement from tkinter?
from tkinter import simpledialog
Without importing simpledialog separately, it throws an error.
Yes, it does throw the error because simpledialog is not directly the module of tkinter.
Basically, the module is every file, which has the file extension .py and consists of proper Python code. There is no special syntax required to make such a file a module. A module can contain arbitrary objects, for example files, classes or attributes. All those objects can be accessed after an import.
If you will do dir(tkinter) without importing the simpledialog explicitly, it shows the results except simpledialog in it.
This is because of the library structure. It doesn't import all the modules of tkinter automatically. Once you use import tkinter.simpledialog it will show you the simpledialog module in it, which means simpledialog was never imported from tkinter earlier.
Also, it is recommended to use import tkinter instead of from tkinter import astrik, except when working in the interactive Python shell. One reason is that the origin of a name can be quite obscure, because it can't be seen from which module it might have been imported.

No module named Tkinter error

I have been using http://python.codnex.net/index.php. I have tried to use Tkinter but it shows ImportError: No module named Tkinter on line 1
I have tried many things including:
import Tkinter
import tkinter
from tkinter import *
If you find something please let me know.
According to this question & answer in Quora you can't use tkinter with online interpreters. Though apparently you can run linux along chromeOS if you have non-school version.
I might be wrong, but I believe it's because tkinter is a GUI module, which can't be ran from a webbrowser.
Have you tried importing it in a local python instance?
it wont work on web browser ,Run a local python instance and import tkinter after installing tkinter by using command prompt using the command pip install python-tk

Use Tkinter in Abaqus 6.12-1 import error

Getting a simple file dialog in abaqus seems pretty difficult, so i wanted to use tkinter. It seems tkinter come with abaqus, but when i try to import the module it says:
File "/opt/Abaqus/6.12-1/tools/SMApy/lib/python2.6/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
importing _tkinter is also not working. so how can one get tkinter to work in abaqus?
Greetings,

Cant Use Tkinter module in setuptools for python2 [duplicate]

I'm trying to compile a program using distutils but I want to make sure that the user has Tkinter installed before installing my package.
My Google searches have failed to turn up any useful info, any clue how I'd do this?
Thanks,
Wayne
You can have a class that inherits from install and then do this:
from distutils.command.install import install
class Install(install):
def run(self):
if not check_dependencies():
# Tkinter was not installed, handle this here
install.run(self) # proceed with the installation
def check_dependencies():
try:
return __import__('Tkinter')
except ImportError:
return None
Unfortunately there is no standard cross-platform way to force Tkinter to be installed. Tkinter is part of the Python standard library so distributors who strip out Tkinter, or other standard library modules, and package them as optional entities are doing so using their own package management tools and, in general, you'd need to know the specific commands for each distribution. The best you can do in general is test for and fail gracefully if Tkinter (or tkinter in Python 3) is not importable, so something like:
import sys
try:
import Tkinter
except ImportError:
sys.exit("Tkinter not found")
Tkinter is in the python standard library, it should always be there.

How do I require Tkinter with distutils?

I'm trying to compile a program using distutils but I want to make sure that the user has Tkinter installed before installing my package.
My Google searches have failed to turn up any useful info, any clue how I'd do this?
Thanks,
Wayne
You can have a class that inherits from install and then do this:
from distutils.command.install import install
class Install(install):
def run(self):
if not check_dependencies():
# Tkinter was not installed, handle this here
install.run(self) # proceed with the installation
def check_dependencies():
try:
return __import__('Tkinter')
except ImportError:
return None
Unfortunately there is no standard cross-platform way to force Tkinter to be installed. Tkinter is part of the Python standard library so distributors who strip out Tkinter, or other standard library modules, and package them as optional entities are doing so using their own package management tools and, in general, you'd need to know the specific commands for each distribution. The best you can do in general is test for and fail gracefully if Tkinter (or tkinter in Python 3) is not importable, so something like:
import sys
try:
import Tkinter
except ImportError:
sys.exit("Tkinter not found")
Tkinter is in the python standard library, it should always be there.

Categories

Resources