You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to Python.Net. I have a HelloWorld.py script:
from tkinter import *
root = Tk()
a = Label(root, text ="Hello World")
a.pack()
root.mainloop()
If I run this script from the command window, it is successful and displays a tkinter window with a "Hello World" label.
If I run this code in Python.Net with VisualStudio:
// latestInstalledVersionDir is pointing to my installed Python directory
// pythonDLL is pointing to "python38.dll"
// libPath is pointing to my installed Python directory\Lib
Runtime.PythonDLL = Path.Combine(latestInstalledVersionDir, pythonDll);
PythonEngine.PythonHome = latestInstalledVersionDir;
PythonEngine.PythonPath = libPath;
PythonEngine.Initialize();
using (Py.GIL())
{
PythonEngine.RunSimpleString(@"
importing tkinter stuff
from tkinter import *
root = Tk()
a = Label(root, text ='Hello World')
a.pack()
root.mainloop()
");
}
I get the error : Traceback (most recent call last):
File "", line 3, in
File "[my user directory]\AppData\Local\Programs\Python\Python38\Lib\tkinter_init_.py", line 36, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
There are many conflicting posts about this error with Python alone. I am not having that issue since when I run the script directly from python with my HelloWorld.py file, it executes successfully. I could not find any resources about this error within Python.Net. Any help would be greatly appreciated.
This discussion was converted from issue #2388 on May 18, 2024 20:58.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Environment
Details
from tkinter import *
root = Tk()
a = Label(root, text ="Hello World")
a.pack()
root.mainloop()
If I run this script from the command window, it is successful and displays a tkinter window with a "Hello World" label.
If I run this code in Python.Net with VisualStudio:
// latestInstalledVersionDir is pointing to my installed Python directory
// pythonDLL is pointing to "python38.dll"
// libPath is pointing to my installed Python directory\Lib
Runtime.PythonDLL = Path.Combine(latestInstalledVersionDir, pythonDll);
PythonEngine.PythonHome = latestInstalledVersionDir;
PythonEngine.PythonPath = libPath;
importing tkinter stuff
from tkinter import *
root = Tk()
a = Label(root, text ='Hello World')
a.pack()
root.mainloop()
");
}
I get the error : Traceback (most recent call last):
File "", line 3, in
File "[my user directory]\AppData\Local\Programs\Python\Python38\Lib\tkinter_init_.py", line 36, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
There are many conflicting posts about this error with Python alone. I am not having that issue since when I run the script directly from python with my HelloWorld.py file, it executes successfully. I could not find any resources about this error within Python.Net. Any help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions