Skip to content

Instantly share code, notes, and snippets.

@aaronkirkman
Created January 25, 2020 19:43
Show Gist options
  • Select an option

  • Save aaronkirkman/edc45b79197037ad570b7174d3547177 to your computer and use it in GitHub Desktop.

Select an option

Save aaronkirkman/edc45b79197037ad570b7174d3547177 to your computer and use it in GitHub Desktop.
Python Xlib code to write to root window
#!/usr/bin/env python3
import secrets
import Xlib
import Xlib.display
import Xlib.X
display = Xlib.display.Display()
screen = display.screen()
root = screen.root
root.change_attributes(event_mask=Xlib.X.ExposureMask)
gc = root.create_gc(foreground = screen.white_pixel, background = screen.black_pixel)
def draw_it():
text = secrets.token_hex(20).encode("utf-8")
root.draw_text(gc, 30, 30, text)
display.flush()
draw_it()
while 1:
if display.pending_events() != 0: # check to safely apply next_event
event = display.next_event()
if event.type == Xlib.X.Expose and event.count == 0:
draw_it()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment