Created
January 25, 2020 19:43
-
-
Save aaronkirkman/edc45b79197037ad570b7174d3547177 to your computer and use it in GitHub Desktop.
Python Xlib code to write to root window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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