Creating user interface with tkinter

Hi everyone,

I’m trying to built a User Interface for my Python Script in Jupyter Notebook.

When I try to execute this simple example
import tkinter
window = tkinter.Tk()
label = tkinter.Label(window, text = “Hello World!”).pack()

I get the following Error:

TclError: no display name and no $DISPLAY environment variable

So my question is: Is it possible to use tkinter in SWAN? And if so, does anyone have an idea how to solve the error?

Thanks a lot!


Hi Julia,

I have no experience with tkinter. However, I have had good experience in making a GUI in a notebook with ipywidgets [1].

Hope that helps, Michał.


Hi Michal,

Thanks a lot for your answer. I was also thinking of ipywidgets which works well!
Why I asked for tkinter is that people without programming background will have access to the tool and I would prefer if they wouldn’t have to scroll through the code until they see the widgets appearing below. But of course that’s not necessary at all, would just be nice-to-have. I will proceed with ipywidgets unless somebody has a solution for tkinter.

Thanks a lot! Julia

Dear Julia,

Tkinter is a relatively old software which is not very suitable for Jupyter notebooks. As Michał suggest, we recommend to use ipywidgets instead.


1 Like