Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Introduction to NiceGUI - A Python based UI framework
Next article icon

Introduction to NiceGUI - A Python based UI framework

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will learn about NiceGUI, It is a Python-based UI Framework, which shows up in Web Browsers and we can create buttons, dialogs, Markdown, 3D scenes, plots, and much more. It works well for dashboards, robotics initiatives, smart house solutions, and other related use cases. Additionally, it can be applied in the creation process, such as when modifying or setting a machine learning method or adjusting motor controllers.

Users only need to take care of the Python code and it will handle the web development i.e GUI details. It is more lightweight than Streamlit and is not only available as a PyPI package but also in Docker. One of the best things about this is that whenever we modify our Python code it will automatically refresh and the changes will be reflected in our browser, no need to manually reload the browser or run the code every time.

Features of NiceGUI

  • Browser-based interaction with a graphical user
  • Standard GUI components like label, icon, checkbox, switch, scale, input, file upload, etc., implicitly refresh when the code is changed.
  • A straightforward organization using rows, columns, cards, and dialogue boxes
  • General-purpose Markdown and HTML components
  • Powerful high-level components to create 3D landscapes, draw graphs and charts, and receive steering inputs from simulated joysticks
  • Engage with tables, comment, and overlay pictures, and traverse foldable tree structures
  • Built-in schedule to periodically update the info (even every 10 ms)
  • Simple data coupling to create even less code
  • Modern user contact is provided by notifications, dialogs, and menus on both public and private online sites.
  • Adding custom paths and data replies
  • Recording keystrokes for use in universal shortcuts, etc.
  • Define main, secondary, and accent colors to create a unique appearance

Required module

To install NiceGUI write the below command in any terminal.

python3 -m pip install nicegui

Simple GUI Program using NiceGUI 

Now we will display a simple hello message using NiceGUI. These messages are known as labels and the method we will use to add any text is also called a label.

Python3
# Importing the module from nicegui import ui  # passing the text we will show ui.label('Hello Geeks from NiceGUI!')  # running it ui.run() 

To run this code simply save it and execute it normally like any other Python code. either using the run button or writing the below command in terminal.

python <filename>.py

This run opens up users' default browser in localhost and every time we make any change to our code just save it and the page will reload automatically, no need to explicitly reload it.

 

Output:

 

We can display some text also using the set_text() method of the label. Even if we have something written inside a normal label, only the text passed in set_text will be shown, and the other one will be replaced.

Python3
from nicegui import ui  # set_text will replace the text # passed in label ui.label('Hello Geeks from NiceGUI!').set_text("This text is passed in set_text")   ui.run() 

Output:

 

Setting visibility of the text

We can explicitly set the visibility of the text using the set_visibility() method, which takes one parameter either True or False.

Python3
from nicegui import ui  ui.label().set_text(text="This text is passed in set_text")  ui.label("Text visible or not").set_visibility(False)  ui.run() 

Output:

 

Adding Icons

Now we will see how we can add icons using NiceGUI using the icon() method.

Python3
from nicegui import ui  ui.label().set_text(text="This text is passed in set_text.")  ui.icon("lock")  ui.run() 

Output:

 

Changing the color and the size of the Icon

Python3
from nicegui import ui  ui.label().set_text(text="This text is passed in set_text.")  ui.icon("lock",color="green",size="50px")  ui.run() 

Output:

Introduction to NiceGUI
 

Users can use any icons available on the Google Fonts website and go to the Icon section. Just pass the name of the font as a parameter and add styling if necessary.

Set the Visibility of the Icon using set_visibility() Method

Visibility is set to False.

Python3
from nicegui import ui  ui.label().set_text(text="This text is passed in set_text.")  # visibility is set to False ui.icon("lock",color="green",size="50px").set_visibility(False)  ui.run() 

Output:

Introduction to NiceGUI
 

Visibility is set to True 

Python3
from nicegui import ui  ui.label().set_text(text="This text is passed in set_text.")  # visibility is set to True ui.icon("lock",color="green",size="50px").set_visibility(True)  ui.run() 

Output:

Introduction to NiceGUI
 

Adding UI Elements

In this example, we are trying to learn how we can insert a toggle, slider, and number container in our GUI web page using NiceGUI using Python.

Python3
from nicegui import ui  class Demo:     def __init__(self):         self.number = 1  demo = Demo() # creating slider ui.slider(min=1, max=5).bind_value(demo, 'number') # creating number ui.number().bind_value(demo, 'number') # creating toggle buttons ui.toggle({1: 'A', 2: 'B', 3: 'C', 4:'D', 5: 'E'}).bind_value(demo, 'number')  ui.run() 

Output:

Introduction to NiceGUI
 

Adding Avatars

We can also add Avatars of our choice, it can be any icon (available Material Icons website) or any downloaded image or URL of an image.

Python3
from nicegui import ui  # The name of these icons is available in Google Fonts or # Material Icons website. Only those names will be recognized  ui.avatar('adb')    ui.run() 

Output:

By default, we can see that the avatar color is black and the background is blue and the structure is a circle. We can change all of them according to our needs.

Introduction to NiceGUI
 

Changing color, background color, size, structure, and shape of the Avatar

Python3
from nicegui import ui   ui.avatar('adb',text_color='green', square=True,color='yellow',size="50px")  ui.run() 

Output:

Introduction to NiceGUI
 

Adding Hyperlink

Now we will see how can we add hyperlinks using NiceGUI. For that, we will use the link() method, which takes two parameters. First, the text will be shown and the second is the link to which the link will redirect after clicking it.

Python3
from nicegui import ui  ui.link("The best Computer Science Portal","https://www.geeksforgeeks.org/")  ui.run() 

Output:

Introduction to NiceGUI
 

Next Article
Introduction to NiceGUI - A Python based UI framework

D

dwaipayan_bandyopadhyay
Improve
Article Tags :
  • Python
  • Python-gui
Practice Tags :
  • python

Similar Reads

    Introduction to JustPy | A Web Framework based on Python
    JustPy is a web framework that leverages the power of Python to create web applications effortlessly. In this article, we'll explore JustPy, its features, and why it's gaining attention among developers. What is the JustPy Module of Python?The JustPy module of Python is a web framework like Django b
    8 min read
    Introduction to Kivy ; A Cross-platform Python Framework
    Kivy is an open-source, cross-platform Python framework used for developing multi-touch applications with a natural user interface. It allows developers to build applications that run on multiple platforms, including Windows, macOS, Linux, iOS, and Android. Kivy is based on the Model-View-Controller
    4 min read
    Introduction to Python for Absolute Beginners
    Are you a beginner planning to start your career in the competitive world of Programming? Looking resources for Python as an Absolute Beginner? You are at the perfect place. This Python for Beginners page revolves around Step by Step tutorial for learning Python Programming language from very basics
    6 min read
    Introduction to pyglet library for game development in Python
    Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc on Windows, Mac OS and Linux. This library is created purely in Python and it supports many features like windowing, user interface event handling, Joysticks, OpenGL graphics, loading
    2 min read
    Python | Introduction to PyQt5
    There are so many options provided by Python to develop GUI application and PyQt5 is one of them. PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences