Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Python Tkinter Project: Random mobile number generator

  • Isha BansalIsha Bansal
  • June 12, 2021
  • Tkinter
Python Tkinter Project: Random mobile number generator

Hello Tkinter coders! Today we are going to learn to build our own random mobile number generator. The application can be really helpful for developers who need some fake data to work on.

Creating a Random Mobile Number Generator in Python

Let’s get right into the steps to create our random number generator using Tkinter. It’s a fun little application that you’ll enjoy working on and somethign you can show off in your beginner portfolios too!

Step 1: Importing Modules and Creating a Tkinter Window

The first step in any Tkinter project is to import the tkinter and random modules and then create a blank window to work on. We can configure the window according to our own preferences.

We will be providing the window with a title and background color. Along with this we will set the resize attributes of the window as false.

import tkinter as tk
window = tk.Tk()
window.geometry("600x200")
window.config(bg="#F39C12")
window.resizable(width=False,height=False)
window.title('Random Mobile Number Generator')

window.mainloop()
Initial Black Screen Tkinter
Initial Black Screen Tkinter

Step 2: Adding Widgets on the Window Created

The step involves addition of various widgets on the window that we just created which include labels and buttons. We will also create a blank label which will be set to the mobile number generated in the later sections.

For each widget, we will be creating the widget variable and then place them on the screen with the help of the place function which requires the x and y coordinates of the widget.

import tkinter as tk
window = tk.Tk()
window.geometry("600x200")
window.config(bg="#F39C12")
window.resizable(width=False,height=False)
window.title('Random Mobile Number Generator')


l1 = tk.Label(text="Random Mobile Number Generator",font=("Arial",20),bg="Black",fg="White")

b1 = tk.Button(text="Click on me to generate a mobile number",font=("Arial",15),bg="#A3E4D7")

l2 = tk.Label(bg="#F39C12",font=("Arial",30),text="")

l1.place(x=100,y=20)
b1.place(x=110,y=70)
l2.place(x=165,y=130)

window.mainloop()
Design Screen Tkinter
Design Screen Tkinter

Step 3: Creating a function to generate a random number

Now coming to creating a function to generate the random number we will be making use of the random module and then create a list that contains all the digits from 0-9 in form of strings stored together.

We would initiate a number variable as an empty string and choose 10 random digits from the list and keep appending them into the number variable. Lastly, we would set the text of the empty string as the number generated.

After that don’t forget to add the function name in the button declaration as the command property. And you are all set!

import random
def generate_number():
    list = ["0","1","2","3","4","5","6","7","8","9"]
    number = ""
    for i in range(10):
        number = number + random.choice(list)
    l2.config(text = number)

The Final Code

import random
def generate_number():
    list = ["0","1","2","3","4","5","6","7","8","9"]
    number = ""
    for i in range(10):
        number = number + random.choice(list)
    l2.config(text = number)

import tkinter as tk
window = tk.Tk()
window.geometry("600x200")
window.config(bg="#F39C12")
window.resizable(width=False,height=False)
window.title('Random Mobile Number Generator')


l1 = tk.Label(text="Random Mobile Number Generator",font=("Arial",20),bg="Black",fg="White")

b1 = tk.Button(text="Click on me to generate a mobile number",font=("Arial",15),bg="#A3E4D7",command=generate_number)

l2 = tk.Label(bg="#F39C12",font=("Arial",30),text="")

l1.place(x=100,y=20)
b1.place(x=110,y=70)
l2.place(x=165,y=130)

window.mainloop()

Some Sample Outputs

Random Number Output 1
Random Number Output 1
Random Number Output 2
Random Number Output 2

Conclusion

Congratulations! Today we learned how to generate mobile numbers using python tkinter technology! Try it out yourself!

Thank you for reading! Stay tuned to learn more!

Isha Bansal
Isha Bansal

Hey there stranger!
Do check out my blogs if you are a keen learner!

Hope you like them!

Articles: 185
Python Pillow Module – A Brief Introduction
Previous Post Python Pillow Module - A Brief Introduction
Next Post How to Count Objects in an Image using Python?
How to Count Objects in an Image using Python?

Related Posts

Tkinter IntVar – Tkinter Tutorial with Examples

Tkinter IntVar – Tkinter Tutorial with Examples

  • July 5, 2026
Tkinter StringVar with Examples – Tkinter Tutorial

Tkinter StringVar with Examples – Tkinter Tutorial

  • July 5, 2026
Tkinter GUI Widgets

Tkinter GUI Widgets

  • April 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.