Show Active Window Name (Python, Tk)

This small Python application shows active window name.

#!/usr/bin/python

# This program is Public Domain
# Make sure you have installed xdotool before executing this (Debian/Ubuntu package "xdotool")

import os
from Tkinter import *

root = Tk()
# This Tk string holds the message string
message = StringVar()
message.set("none")

# Store update ID to this global var
update_id=None

# Show label and get content from variable "message"
w = Label(root, textvariable=message)
w.pack()

# Create Exit button
button_cancel = Button(root, text="Dismiss", command=root.quit)
button_cancel.pack()

def update_message():
    message.set(os.popen('/usr/bin/xdotool getwindowfocus getwindowname').read())
    update_id=root.after(1000, update_message)

update_id=root.after(1000, update_message)
root.mainloop()

Leave a Reply

Your email address will not be published. Required fields are marked *