Azad Rasul
SmartRS

SmartRS

24- Add a time button to a toolbar

Azad Rasul's photo
Azad Rasul

Published on Jun 20, 2021

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Download icon image of time

import os
from datetime import datetime

# path of icon
icon = 'time.png'
data_dir = os.path.join(os.path.expanduser('~'), 'D://', 'Python_QGIS')
icon_path = os.path.join(data_dir, icon)

# define Baghdad local time
def WhatTime():
    tz_Ba = pytz.timezone('Asia/Baghdad') 
    now = datetime.now(tz_Ba)
    current_time = now.strftime("%H:%M:%S")
    iface.messageBar().pushInfo('Baghdadt Time', current_time)

action = QAction('What time is it?')
action.triggered.connect(WhatTime)
action.setIcon(QIcon(icon_path))
iface.addToolBarIcon(action)
 
Share this
Proudly part of