Rectangles
Lesson 19: Drawing Rectangles with fill colors
from fltk import *
class MyApp(Fl_Window):
def __init__(self, x,y, w, h, label=None):
Fl_Window.__init__(self, x, y, w, h, label)
self.color(FL_BLACK)
self.end()
self.sqrsiz=100
def handle(self, event):
r=super().handle(event)
if event==FL_RELEASE:
x=Fl.event_x()
y=Fl.event_y()
if ((x//self.sqrsiz)+(y//self.sqrsiz))%2 == 1 :
print('Black')
else:
print('White')
return 1
return r
def draw(self):
Fl_Window.draw(self)
color=[FL_WHITE,FL_DARK3]
#color=[7,0]
for x in range(0,self.w(),self.sqrsiz):
for y in range(0, self.h(), self.sqrsiz):
c=color[(x+y)//100%2]
fl_rectf(x,y,self.sqrsiz,self.sqrsiz,c)
height=500
app = MyApp(0,0, height, height)
app.show()
Fl.run()