- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Using Tkinter in Jupyter Notebook
Tkinter is a Python library used for creating and developing GUI-based applications. It is completely open-source which works on Windows, Mac, Linux, and Ubuntu. In Windows operating system, we can install the Tkinter library using the command pip install tkinter. It will install all the other modules that come with Tkinter library. Tkinter can be installed on Jupyter notebook as well, by using the command pip install tkinter. We can run all the standard commands of Tkinter in Jupyter notebook.
Once we have installed Tkinter in Jupyter notebook, then we can verify the installation by typing the following command −
from tkinter import *
Now, after verifying the installation, you are ready to write your Tkinter application code in Jupyter notebook. For example, type the following code in Jupyter notebook and run the code by pressing "Shift + Enter".
Example
#Import tkinter library from tkinter import * #Create an instance of Tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") def callback(): Label(win, text="Hello World!", font=('Century 20 bold')).pack(pady=4) #Create a Label and a Button widget btn=Button(win, text="Press Enter", command= callback) btn.pack(ipadx=10) win.bind('<Return>',lambda event:callback()) win.mainloop()
Output
Running the above code will display a window that contains a button widget.
In the given output, when we press the Enter key, it will show the Label widgets with some text.
- Related Articles
- Create a simple Numpy Jupyter Notebook using Docker
- Hide Matplotlib descriptions in Jupyter notebook
- How to change the figsize for matshow() in Jupyter notebook using Matplotlib?
- How to start tensorflow Docker jupyter notebook?
- Displaying rotatable 3D plots in IPython or Jupyter Notebook
- Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)
- Programmatically Stop Interaction for specific Figure in Jupyter notebook
- Notebook widget in Tkinter
- How do I omit Matplotlib printed output in Python / Jupyter notebook?
- How to display a Dataframe next to a Plot in Jupyter Notebook?
- How to show numpy 2D array as grayscale image in Jupyter Notebook?
- How to remove Ttk Notebook Tab Dashed Line? (tkinter)
- Save figure as file from iPython notebook using Matplotlib
- Color game using Tkinter in Python
- Develop Notepad using Tkinter in python
