0

Hello my fellow programmers,

I want to include a script from another file that creates a UI with iPyWidgets. The problem is that the code will execute but nothing is shown. I am using Jupyterhub to display the button. When I run the code on itself, the button is showing.

button_code.py

from ipywidgets import widgets
from IPython.display import display
from IPython.display import clear_output
from ipywidgets import Button, HBox, VBox, Layout, Button, Text, Textarea

widgets.Button(description = 'clear',
layout=Layout(width='20%', height='100%'))

call_button_script.py

import os
def call_script():

    script_dir = os.path.dirname(os.path.abspath(__file__))
    script_fqn = os.path.join(script_dir, 'button_code.py')
    script = open(script_fqn).read()

    exec(script, globals())

The code is executed via the following import:

from call_button_script import call_script
call_script()

Am I missing something crucial or is there another possible mistake?

Thank you for your time.

Derek Haynes
  • 125
  • 1
  • 2
  • 13

2 Answers2

0

Is your from call_button_script import call_script call_script() in the same directory ? did you've seen the output on the console

amalcodes
  • 43
  • 5
  • Yes I can see output on the console when doing a print statement for example. Just the widget will not show. Also when I return the widget I have no possibility to let it display – Derek Haynes Jan 19 '20 at 08:24
0

The answer was to just import the whole file. I´ve put it in a class and initialized it all in the init

The GUI wasn´t showing because it was missing display() in the code

Derek Haynes
  • 125
  • 1
  • 2
  • 13