In [ ]:
%gui
In [1]:
from PyQt5 import QtWidgets
In [ ]:
b1 = QtWidgets.QPushButton("Click Me")
A pop up will appear saying
The kernel appears to have died and will restart automatically
In the terminal, you can also see the following message
QWidget: Must construct a QApplication before a QWidget
[I 11:26:36.051 NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 08b46e93-bcf2-49ce-af69-0979e879b7e2 restarted
In [1]:
%gui qt5
In [2]:
from PyQt5 import QtWidgets
In [3]:
b1 = QtWidgets.QPushButton("Click Me")
In [4]:
b1.show()
In [5]:
def on_click_cb():
print("Clicked")
In [6]:
b1.clicked.connect(on_click_cb)
Now, if you click the button, the callback will be called.
And since Jupyter Notebook is awesome the output will be displayed in the cell's output area (Look at the output area for the previous cell!)
In [1]:
%connect_info
In [2]:
!jupyter kernel list
In [7]:
%qtconsole
Now the Jupyter QtConsole will be started by connecting to the ipython kernel that is already running.
You do not believe it?
Well just type the magic %whos to see the truth.
You can redisplay the button now!!
I prefer continuing to work in the notebook, so I will close the button and also the QtConsole.
Pay close attention to the message in the dialog box.
Back in the Notebook turf, you can redisplay the button and continue clicking.
In [10]:
b1.show()