Python : Repeatedly showing tkinter message box using schedule. Schedule a Python script to run daily 🔥🔥

Hi all,

Today in this article we are going to discuss about how to pop up the message box repeatedly with schedule module and tkinter module

Those who has not read mine article on tkinter they can visit tkinter series page – https://knowledge-junction.com/dashboard/python-gui-programming-with-tkinter-complete-tutorials/

If anyone wants to know more about pip can read this article – https://knowledge-junction.com/2021/07/25/most-popular-tool-for-installing-python-packages-pip/

Our Python pygame series can make games with Python – https://knowledge-junction.com/dashboard/python-pygame-series/

So let’s begin

  • We will pop up the message using tkinter module so lets import it
# Importing tkinter module
import tkinter

  • We are going to use message box from tkinter. We will import messagebox
# Importing messagebox from tkinter
import tkinter.messagebox

  • To show our message box after an any time interval we will import schedule and time
# Importing time module 
import time

# Importing schedule module
import schedule

  • Now we will make a function in which we will show our message box
# Function setup
# Defining drink water function

def drinkwater():


# It will display messagebox
# Title of the box - Drink water
# Message to show - Drink 1 glass of water

    tkinter.messagebox.showinfo("Drink water", "Drink 1 glass of water")

We can create different GUI widgets like messagebox in tkinter in our tkinter article we have mentioned about all the basic widgets in tkinter you can checkout the link is given

  • We will schedule our function in how many time it should show message
# Task scheduling
# After every hour drinkwater() is called.

schedule.every(1).hours.do(drinkwater)

  • Then we will make loop so it should pop up the message after an specific time interval given
while True:
 
    # Checks whether a scheduled task
    # is pending to run or not

    schedule.run_pending()
    time.sleep(1)

Full Code

# Importing tkinter module
import tkinter

# Importing messagebox from tkinter
import tkinter.messagebox

# Importing time module 
import time

# Importing schedule module
import schedule

# Function setup
# Defining drink water function

def drinkwater():


# It will display messagebox
# Title of the box - Drink water
# Message to show - Drink 1 glass of water

    tkinter.messagebox.showinfo("Drink water", "Drink 1 glass of water")

# Task scheduling
# After every hour drinkwater() is called.

schedule.every(1).hours.do(drinkwater)

while True:
 
    # Checks whether a scheduled task
    # is pending to run or not

    schedule.run_pending()
    time.sleep(1)

Output

Now after every hour it will display the messagebox

Fig : 1 Python : Displaying messagebox
Fig : 1 Python : Displaying messagebox

You can visit on my GitHub page where you will get the source code file – https://github.com/Sayyam936/CodeWithSayyam.git

Thank you🙂

Have a nice day!!

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: