Is it possible to open Napari (in full-screen mode) from a script?


I am running a python script as follows:
It works fine, it opens the Viewer in the default size, but I would to open the viewer in full-screen size. Is this possible?

According to the help, there is not such option:

napari --help
napari command line viewer.

positional arguments:
paths path(s) to view.

optional arguments:
-h, --help show this help message and exit
-v, --verbose increase output verbosity
–version show program’s version number and exit
–info show system information and exit
–citation show citation information and exit
–stack concatenate multiple input files into a single stack.
–plugin PLUGIN specify plugin name when opening a file
–layer-type TYPE force file to be interpreted as a specific layer type. one of {‘image’,
‘vectors’, ‘shapes’, ‘labels’, ‘points’, ‘surface’}

optional layer-type-specific arguments (precede with ‘–’):
attenuation, blending, channel-axis, colormap, contrast-limits, data,
gamma, interpolation, iso-threshold, metadata, multiscale, name,
opacity, rendering, rgb, scale, translate, visible
blending, color, data, metadata, multiscale, name, num-colors,
opacity, properties, scale, seed, translate, visible
blending, data, edge-color, edge-color-cycle, edge-colormap,
edge-contrast-limits, edge-width, face-color, face-color-cycle,
face-colormap, face-contrast-limits, metadata, n-dimensional, name,
opacity, properties, scale, size, symbol, text, translate, visible
blending, data, edge-color, edge-color-cycle, edge-colormap,
edge-contrast-limits, edge-width, face-color, face-color-cycle,
face-colormap, face-contrast-limits, metadata, name, ndim, opacity,
properties, scale, shape-type, text, translate, visible, z-index
blending, colormap, contrast-limits, data, gamma, metadata, name,
opacity, scale, translate, visible
blending, data, edge-color, edge-color-cycle, edge-colormap,
edge-contrast-limits, edge-width, length, metadata, name, opacity,
properties, scale, translate, visible

Thank you very much! :wink:

We don’t support that yet, but we could add a -f or --fullscreen option. cc @jni

Thank you very much @sofroniewn!. I vote +1 for that new features :slight_smile:
By the way, if I run the script as “napari”, this opens one viewer as expected, but if I run the script as “python”, this opens two viewers, one of them is totally empty and the other one shows the images. This discrepancy of usage is a little bit strange, is this the expected behaviour?

The code of the script is the following:

import napari

with napari.gui_qt():

viewer = napari.Viewer()

layer1 ='example_TE.zarr', layer_type='image', multiscale=True, contrast_limits=[0, 1], rgb=False)

layer2 ='example_bin_labels.zarr', layer_type='labels', multiscale=True)

points = viewer.add_points(

Hmm no that’s no expected. If you comment out some lines in your example does it still happen? The calls should all go to the only viewer you have already created.

Yeah I’m wondering if you can provide a minimal example that reproduces the problem with just generated data, rather than depending on your data files. (Or alternatively, provide the data files in a zip file, if they are reasonably sized…)

Thank you very much @sofroniewn and @jni,
This behavior is more strange than what I initially thought, the strange behavior only occurs when the filename of the script is If I replace that name by simply, it works as expected (only one viewer).

import numpy as np
import zarr
from skimage.transform import pyramid_gaussian
import napari

def generate_pyramid_zarr(fname, N=1000):

data = np.random.rand(N, N)

pyramid_data = list(
    pyramid_gaussian(data, downscale=2, max_layer=3, multichannel=False)

root = zarr.open_group(fname, mode='w')
for i in range(len(pyramid_data)):
    shape = pyramid_data[i].shape
    dtype = pyramid_data[i].dtype
    z = root.create_dataset(str(i), shape=shape, dtype=dtype, chunks=(300, 300))
    z[:] = pyramid_data[i]

generate_pyramid_zarr(‘example1.zarr’, N=1000)

with napari.gui_qt():

viewer = napari.Viewer()
    contrast_limits=[0, 1], 

Could you please try to save this example as, and then run it as

Could you please rename the file now as and run it again as

Well that is interesting!! Thanks, I will try and reproduce.

Just as a reference, in case another beginner user like me is interesting in opening Napari in full-screen mode, you can do so as follows:

import sys
import napari
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QApplication

app = QApplication()

viewer = napari.Viewer(show=False)


Please note that I am assuming the script does not receive any console inputs.

Ah if you want full screen mode from a script - not just the command line - then you can do

import napari

with napari.gui_qt():
    #viewer.window._qt_window.showNormal() # returns viewer to normal mode

In my original answer I was thinking you wanted a command line option, my apologies for not providing this answer sooner.

1 Like

Thank you very much @sofroniewn!, and please excuse me for my ambiguous question :blush: … Even though I am a beginner user, I like the project a lot!, I am digging into the source code to understand more and more the inner working of Napari, and while doing so I found a possible answer to my question, so I decided to share it here in the forum in case another beginner user was also looking for a similar answer ;).

Thank you very much for all your help!

1 Like