Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Problem showing Tk filedialog using python in NX 10

I'm trying to run some sample code to display a file open dialog using a python journal in NX 10.

 

sample code:

import tkinter as tk
from tkinter import filedialog

root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()

 

The code runs fine outside of NX but as a journal I receive this error like it cannot find the Tcl library. Not of the paths listed in the error dialog exist.

 

The paths listed are:

C:/Siemens/nx10/ugii/lib/tcl8.5

C:/Siemens/nx10/lib/tcl8.5

C:/Siemens/lib/tcl8.5

C:/Siemens/nx10/library

C:/Siemens/library

C:/Siemens/tcl8.5.11/library

C:/tcl8.5.11/library

 

My python overrides are:

UGII_PTYHON_LIBRARY_DIR

C:\Siemens\nx10\ugii\python

 

UGII_PYTHONPATH

C:\Siemens\nx10\ugii\python;C:\Siemens\nx10\ugii\python\Python33.zip

 

Thanks,

Carl

4 REPLIES
Solution
Solution
Accepted by topic author cmarcum
‎12-17-2015 04:57 PM

Re: Problem showing Tk filedialog using python in NX 10

To use Tk, you need a standalone python installation containing the tcl libraries. You also need to define the TCL_LIBRARY environment variable to point to the tcl8.5 location.

 

See "Python environment setup" in the Release Notes (NX 10 Caveats and Product Notes > Programming Tools > Product Notes):

 

https://docs.plm.automation.siemens.com/tdoc/nx/10/release_notes/#uid:index_xid850184:xid862140:xid3...

Re: Problem showing Tk filedialog using python in NX 10

That worked !

 

Thanks Jim

Re: Problem showing Tk filedialog using python in NX 10

I have a similar problem with tkinter on NX11

 

Using the same filedialog:

import tkinter as tk
from tkinter import filedialog

root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()

This works just fine outside of NX

But in NX11 produces errors:

 

Line 1795: Traceback (most recent call last):
  File "C:\Users\MyUserName\AppData\Local\Temp\Journal0738BFE0gpob.py", line 4, in <module>
    root = tk.Tk()
  File "C:\Python34\Lib\tkinter\__init__.py", line 1795, in __init__
    baseName = os.path.basename(sys.argv[0])
AttributeError: 'module' object has no attribute 'argv'

 

Using external Python Interpreter 3.4

 

My Paths:

UGII_PYTHON_HOME=C:\Python34\

UGII_PYTHON_DLL=python34.dll

UGII_PYTHON_LIBRARY_DIR=C:\Python34\

UGII_PYTHONPATH=C:\Python34;C:\Python34\DLLs;C:\Python34\Lib;C:\Python34\libs;C:\Python34\Lib\site-packages;C:\siemens\NX11\NXBIN\python;

TCL_LIBRARY=C:\Python34\tcl\tcl8.6

Re: Problem showing Tk filedialog using python in NX 10

This script runs properly for me in both NX 10 and NX 11 (assuming each is configured with the appropriate version of Python)