Code: Alles auswählen
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import random
class pyLGS:
def delete_event(self, widget, data=None):
print "delete event occured"
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
# Main self.window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("pyLGS - Lineare Gleichungssysteme")
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(10)
# Box
self.hbox = gtk.HBox(False, 5)
self.vbox = gtk.VBox(False, 5)
self.window.add(self.hbox)
self.hbox.pack_start(self.vbox, False, False, 0)
# Label
self.label1 = gtk.Label()
self.vbox.pack_start(self.label1, False, False, 0)
self.label2 = gtk.Label()
self.vbox.pack_start(self.label2, False, False, 0)
# Button
self.button = gtk.Button("Go")
self.button.connect("clicked", self.lgs, None)
self.vbox.pack_start(self.button, False, False, 0)
self.vbox.show()
self.hbox.show()
self.window.show_all()
def main(self):
gtk.main()
def lgs(self, widget, data=None):
x = random.randint(1,10)
y = random.randint(1,10)
a = random.randint(1,10)
b = random.randint(1,10)
c = a*x + b*y
n = random.randint(2,10)
m = random.randint(2,10)
d = n*a*x + m*b*y
#print a, "x + ", b, "y = ",c
#print n*a, "x + ", m*b, "y = ",d
self.label1.set_text = "%dx + %dy = %d" % (a, b, c)
self.label2.set_text = "%dx + %dy = %d" % (n*a, m*b, d)
if __name__ == "__main__":
pyLGS = pyLGS()
pyLGS.main()