home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / tkinter / matt / canvas-reading-tag-info.py < prev    next >
Text File  |  1996-07-30  |  1KB  |  50 lines

  1. from Tkinter import *
  2.  
  3.  
  4. class Test(Frame):
  5.     def printit(self):
  6.     print "hi"
  7.  
  8.     def createWidgets(self):
  9.     self.QUIT = Button(self, text='QUIT', foreground='red', 
  10.                command=self.quit)
  11.     self.QUIT.pack(side=BOTTOM, fill=BOTH)
  12.  
  13.     self.drawing = Canvas(self, width="5i", height="5i")
  14.  
  15.     # make a shape
  16.     pgon = self.drawing.create_polygon(
  17.         10, 10, 110, 10, 110, 110, 10 , 110,
  18.         fill="red", tags=("weee", "foo", "groo"))
  19.  
  20.     # this is how you query an object for its attributes 
  21.     # config options FOR CANVAS ITEMS always come back in tuples of length 5.
  22.     # 0 attribute name
  23.     # 1 BLANK 
  24.     # 2 BLANK 
  25.     # 3 default value
  26.     # 4 current value
  27.     # the blank spots are for consistency with the config command that 
  28.     # is used for widgets. (remember, this is for ITEMS drawn 
  29.     # on a canvas widget, not widgets)
  30.     option_value = self.drawing.itemconfig(pgon, "stipple")
  31.     print "pgon's current stipple value is -->", option_value[4], "<--"
  32.     option_value = self.drawing.itemconfig(pgon,  "fill")
  33.     print "pgon's current fill value is -->", option_value[4], "<--"
  34.     print "  when he is usually colored -->", option_value[3], "<--"
  35.  
  36.     ## here we print out all the tags associated with this object
  37.     option_value = self.drawing.itemconfig(pgon,  "tags")
  38.     print "pgon's tags are", option_value[4]
  39.  
  40.     self.drawing.pack(side=LEFT)
  41.  
  42.     def __init__(self, master=None):
  43.     Frame.__init__(self, master)
  44.     Pack.config(self)
  45.     self.createWidgets()
  46.  
  47. test = Test()
  48.  
  49. test.mainloop()
  50.