Created
March 19, 2014 18:58
-
-
Save petrblahos/9648800 to your computer and use it in GitHub Desktop.
Small Gtk app that toggles images according to the button state.
This file contains 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
from gi.repository import Gtk | |
class LedControl(Gtk.Window): | |
""" | |
A simple app that changes images according to the button status. | |
""" | |
def __init__(self): | |
Gtk.Window.__init__(self, title="LED Control") | |
self.set_border_width(6) | |
self.set_default_size(200, 250) | |
okno = Gtk.Table(4, 2, True) | |
self.add(okno) | |
self.leds = [] | |
for i in range(4): | |
button = Gtk.ToggleButton("LED %s" % i) | |
button.connect("toggled", self.led_button_handler, str(i)) | |
button.set_border_width(2) | |
img = Gtk.Image() | |
img.set_from_file("LED_off.png") | |
okno.attach(button, 0, 1, i, i + 1) | |
okno.attach(img, 1, 2, i, i + 1) | |
self.leds.append(img) | |
def led_button_handler(self, button, name): | |
self.leds[int(name)].set_from_file( | |
"LED_on.png" if button.get_active() else "LED_off.png", | |
) | |
if "__main__" == __name__: | |
app = LedControl() | |
app.connect("delete-event", Gtk.main_quit) | |
app.show_all() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment