cpython/Demo/tkinter/matt/canvas-w-widget-draw-el.py

37 lines
1.0 KiB
Python
Raw Normal View History

1994-10-07 09:55:26 +00:00
from Tkinter import *
# this file demonstrates the creation of widgets as part of a canvas object
class Test(Frame):
def printhi(self):
print "hi"
def createWidgets(self):
1996-07-30 18:57:18 +00:00
self.QUIT = Button(self, text='QUIT', foreground='red',
command=self.quit)
self.QUIT.pack(side=BOTTOM, fill=BOTH)
1994-10-07 09:55:26 +00:00
1996-07-30 18:57:18 +00:00
self.draw = Canvas(self, width="5i", height="5i")
1994-10-07 09:55:26 +00:00
1996-07-30 18:57:18 +00:00
self.button = Button(self, text="this is a button",
command=self.printhi)
1994-10-07 09:55:26 +00:00
# note here the coords are given in pixels (form the
# upper right and corner of the window, as usual for X)
# but might just have well been given in inches or points or
# whatever...use the "anchor" option to control what point of the
# widget (in this case the button) gets mapped to the given x, y.
# you can specify corners, edges, center, etc...
1996-07-30 18:57:18 +00:00
self.draw.create_window(300, 300, window=self.button)
1994-10-07 09:55:26 +00:00
1996-07-30 18:57:18 +00:00
self.draw.pack(side=LEFT)
1994-10-07 09:55:26 +00:00
def __init__(self, master=None):
Frame.__init__(self, master)
Pack.config(self)
self.createWidgets()
test = Test()
test.mainloop()