Why doesn't this work?
Michael Bakkemo
a at b.c
Sun Sep 29 02:29:12 EDT 2002
Why doesn't the rectangle start somewhere in the middle of the canvas (where
one would expect (40,40) to be, instead of all the way over on the left?
---
import Tkinter
import Pmw
import tkFont
class MovingRect:
def __init__(self, master, sc, x, y,width, height):
self.master = master
self.sc = sc
self.x = x
self.y = y
self.width = width
self.height = height
self.rectID = self.sc.create_rectangle(self.x, self.y,
self.x+self.width, self.y+self.height,fill="black", outline="black")
self.poll()
def poll(self):
sc.move(self.rectID, 4, 0)
self.timerID = self.master.after(500, self.poll)
def width(self, width):
self.width = width
def height(self, height):
self.height = height
def Destroy(self):
self.master.after_cancel(self.timerID)
def bail():
menu.quit()
rect.Destroy()
root = Tkinter.Tk()
# create a menu
menu = Tkinter.Menu(root)
root.config(menu=menu)
Quitmenu = Tkinter.Menu(menu)
menu.add_cascade(label="Quit", menu=Quitmenu)
Quitmenu.add_command(label="Quit", command=bail)
sc = Pmw.ScrolledCanvas(root, borderframe=1, hscrollmode='dynamic',
vscrollmode='dynamic')
sc.xview("moveto", 0)
sc.yview("moveto", 0)
sc.resizescrollregion()
sc.pack(fill='both',expand=1)
rect = MovingRect(root, sc, 40,40, 10, 10)
root.mainloop()
More information about the Python-list
mailing list