Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

Creating User Input Dialog With Python GUI Programming

1 min read

In this tutorial, we will create a dialog which takes input from the user and prints it in the terminal, the purpose of this tutorial is to understand how to take the user input for GUI application.

We will use the built-in Python package Tkinter it is implemented as a Python wrapper for the Tcl Interpreter embedded within the interpreter of Python.

Creating User Input Dialog With Tkinter

import tkinter as tk
from tkinter import simpledialog

ROOT = tk.Tk()
# the input dialog
USER_INP = simpledialog.askstring(title="Test",
                                  prompt="What's your Name?:")
# check it 
outprint("Hello", USER_INP)

Save the file you should see the following input dialog asking for your name.

Creating user input dialog with python and TKinter
Enter your name here it should be printed in the terminal along with the message.

Hello Tony


First, we are importing the Tkinter module, then we are creating a window in the ROOT object.

Next, we have the withdraw() method which removes the window from the screen (without destroying it).

Later we are taking the user from the user using askstring() method which simply takes the string entered.

At the bottom, we printing out the Hello string along with the user input.


Latest Articles

Latest from djangocentral

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read