Can you please let me know how to download tkinter for windows 7 64bit. I am getting an error while i do it:
from Tkinter import *)
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
from Tkinter import *
ImportError: No module named 'Tkinter'
If you are using python 3 then the code would use a lower case tkinter.
#python 2
from Tkinter import *
#python 3
from tkinter import *
if that doesn't fix it then you can install it in several ways. check out this page: http://www.tkdocs.com/tutorial/install.html
If you can't get that to work another option is using pip. pip allows you to install modules easily. If you have the newest version if python 2 then it is installed and all you have to do is set a path. Click the start button and right click on computer. Select properties and then advanced settings. Under one of the tabs is a button called environment variables. Click on it and in the new windows scroll down until you see the word "path" on the right. Click on the text to the left of it and put in a ; to put in a new path. I don't know exactly how your file structure is but find python and set a path to the folder called scripts within python. An example would be something like this: "C:\python27\scripts".
There are two possible reasons that you are not able to get Tkinter working:
First Reason
First, this is dependent on if you have installed tk onto your computer. To find out if you have, and what version, run a Python shell via:
% C:\python32\python
From the Python command prompt, enter these two commands:
>>> import tkinter
>>> tkinter._test()
This should pop up a small window; the first line at the top of the window should say "This is Tcl/Tk version 8.5"; Or whatever version has been installed on your computer. If you haven't installed, you'll want to get tkinter on there. I've found the following that may help with that:
http://www.tkdocs.com/tutorial/install.html
Second Reason
If installing tkinter onto your machine isn't the issue, then this is most likely due to what version of python you are using, as this will change some small things.
Python 3:
from tkinter import *
Python 2.7:
from Tkinter import *
If you have python you are trying to run from 2.7 or before but are using it in Python 3, you may find the 2to3 tool helpful for adapting:
https://docs.python.org/2/glossary.html#term-to3
open IDLE Python GUI and type in import tkinter and after that type import_tkinter and if you wanna run a test just type in tkinter._test()
works for python 3.4.3
Related
I have a tkinter GUI that allows me to start any kind of program:
# main_app.py
import tkinter as tk
import subprocess
root = tk.Tk()
cmd_entry = tk.Entry(width=50)
cmd_entry.pack(side='left')
def run_script():
sp = subprocess.run(cmd_entry.get().split(), shell=True)
run_btn = tk.Button(text="Run Command", command=run_script)
run_btn.pack(side='left')
root.mainloop()
It looks like this:
I can start another tkinter script from this window, for instance:
# dummy_app.py
import tkinter as tk
root = tk.Tk()
root.mainloop()
It even works when starting dummy_app.py with a different version of python. For example, I can start main_app.py with Python 3.10.8 and run the following:
C:\Path\to\python3.9\python.exe dummy_app.py
However, if I compile main_app.py into an executable with pyinstaller (v5.6.2):
pyinstaller.exe .\main_app.py --onefile
Then I get the following error when trying to run C:\Path\to\python3.9\python.exe dummy_app.py from main_app.exe:
C:/Users/.../AppData/Local/Temp/_MEI76562/tcl/init.tcl: version conflict for package "Tcl": have 8.6.9, need exactly 8.6.12
version conflict for package "Tcl": have 8.6.9, need exactly 8.6.12
while executing
"package require -exact Tcl 8.6.12"
(file "C:/Users/.../AppData/Local/Temp/_MEI76562/tcl/init.tcl" line 19)
invoked from within
"source C:/Users/.../AppData/Local/Temp/_MEI76562/tcl/init.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $tclfile]"
This probably means that Tcl wasn't installed properly.
python dummy_app.py works fine however.
Why does the tcl version has to be the same when starting the script from the compiled executable? Is there a way around this?
The version of the Tcl support scripts used inside Tkinter must exactly match the version of the Tcl and Tk binary libraries used. Bugfixes may be applied in either location, but the version matching must be exact; they're matched parts a single software product.
The workaround is not to cross-match. If you bind the version in one place (e.g., with linking options) then you must bind it in the other (e.g., by shipping the script files).
We're working on making future versions (8.7 onwards) have this binding done at link time; almost all scenarios don't need significant rewriting of internal scripted parts of Tcl and Tk's implementations.
I have a code, where i use tkinter to make a window and stuff. It's a brawler picker for brawl stars. Im using pop os-linux and vs code and i have tried so many ways, but anything doesn't work.
When i run the code, i get this:
(.venv) sh-5.1$ python -u "/home/"my_name"/Documents/Vs-code_projektit/Joku.py"
Traceback (most recent call last):
File "/home/"my_name"/Documents/Vs-code_projektit/Joku.py", line 2, in <module>
from tkinter import *
ModuleNotFoundError: No module named 'tkinter'
And in the vs code itself, it regognizes the tkinter and turns the text green, but after that nothing relating to tkinter doesn't work and i shows an error. Btw i have the full code already cause i copied from my dual boot windows and i wanted to try it here,
What should i do to make it work?
EDIT:
For everybody who has the same problem, it may be caused by the app version. I posted this on reddit cause i didn't get answer in time, and someone suggested that i download vs code with appimage, snap, or in my case pop!_os Installation.
MAIN POINT: Someone said that NEVER use FLATPACK with ides. It may work for other apps but never use it with ides. It can't handle system packages or modules.
First of all, you need to know what interpreter is currently used by vscode, which is displayed in the lower right corner of the interface.
Clicking on the displayed python version will open a Select Interpreter panel where you can select the interpreter with the tkinter package installed to run the code
Or you can install the tkinter package for the currently used interpreter.
<path-to-current-python.exe> -m pip install tkinter
EDIT
From your terminal information it can be seen that you have activated the virtual environment, but you are running the code with Code Runner.
As a reminder, Code Runner doesn't change interpreters as you select another interpreter in the Select Interpreter panel. So please use the Run Pythonn File option provided by the official Python extension to run the code.
I'm new to using atom and was wondering how to run a python script on it. I have code written at the moment which works perfectly fine in normal python shell, using tkinter, however when I run it through the command line, it says:
import tkinter as tk
ImportError: No module named tkinter
How do I fix this? In my environment variables I have already added python.exe, the file directory to the actual script I'm running and to the python download itself. How do I fix this?
The best way is to load the Jupyter plugin. It's called Hydrogen. Then under the packages menu, you can select Hydrogen/Run all and it will run your python code. there is a keyboard shortcut for doing this which speeds up the process. You can easily check your code as you write it by using the hydrogen option to run a line and go to next line.
As for your Tkinter problem have you loaded Tkinter? You can do this using pip install Tkinter. After that try running your code again.
In python 2.7 and below, the modules's name is Tkinter, while in 3.0 and above, it is tkinter.
Atom (whatever this is) seems to use a 2.7 or below version of python interpreter.
I'm using tkinter to build gui with my mac.normally I'm using python IDLE to run and test the code. I created a new file with .py extension and run it. it works properly. this is the code.
from tkinter import *
mywin = Tk();
mywin.title("window for mac")
This works fine
Then I tried to run the file using terminal and tried to launch the file with python launcher.at that time it gives following error
File "check.py", line 1, in <module>
from tkinter import *
ImportError: No module named tkinter
my python version is Python 2.7.10. some says it is corruption on python. I tried to install python with home-brew also.but didn't get any result.
Idle and Terminal python version are different !
Need using same version of Python.
No module named tkinter is python2.X error ! No module named Tkinter is python3.X error.
I have a tkinter script, which runs just fine in IDLE. However, when I double click the .py-file from Windows Explorer, the console window flashes half a second and then it exits.
I was able to screenprint the console window. It says:
...etc.etc...
NameError: global name 'simpledialog' is not defined
simpledialog is a module in tkinter which I use in my script. As I do from tkinter import *, there is no need to explicitly write tkinter.simpledialog.
It works in IDLE, why not as .py?
IDLE uses Tkinter as its graphical environment. It is possible that your code is relying on a side effect of an import by IDLE itself. This is especially true if you use IDLE without a subprocess.
The simpledialog module does not import when using from tkinter import *.
Try adding this to your code:
import tkinter.simpledialog as simpledialog
Have you updated your PATH environment variable so that your Python executable is found? You can find more information on how to do here - Using Python on Windows
But you basically need to make sure that the folder containing python.exe (e.g. C:\Python32) is displayed when you type the following command from a prompt:
echo %PATH%
I had exactly the same problem with one of my scripts utilizing Tkinter.
Adding call to mainloop() fixed the issue.
See this tutorial for an example: [http://sebsauvage.net/python/gui/#import1
In my case, in the init function I have
def __init__(self,Width=400, Height=400):
# Create GUI window ------------------------------
win = Tk()
...
in the end of init I added:
win.mainloop()
Now it works by just running the file.
Hope this helps
Similar trouble for me just now, in my first week with python. But I dimly remembered a similar problem with a simple early test script and thought the trouble then was # comments.
So I tried that with my Tkinter infused .py script. It ran fine in IDLE as you say, then only flashed when clicked in windows. But there were a couple # commented lines at the top of file.
I took them all out and it now runs no sweat directly in windows. Have a look .. for #.
Sorry, can't seem to delete this post. Now the files work #comments included. Don't know what's up with that. ..
I found that changing the executable py file to a file.pyw fixed the problem. This tells python to execute it using the pythonw.exe which runs the script without the terminal/console in the background.
Not sure why this works, perhaps some screwed up environment variables from a previous python installation.
Changing the file's extension to pyw instead of py might solve the problem