Tkinter: Strange behavior using place() and changing cursors

Mudcat mnations at gmail.com
Mon Nov 13 20:24:24 EST 2006


I was trying to design a widget that I could drag and drop anywhere in
a frame and then resize by pulling at the edges with the mouse. I have
fiddled with several different approaches and came across this behavior
when using the combination of place() and configure(cursor = ...) This
problem doesn't occur if you remove either one of these elements.

It's a very basic design of a button wrapped in a sizer frame and is
supposed to work like any window that can be resized. The mouse will
change into a resize cursor when it hits the sizer frame (button's
edge).

However when the cursor hits the right edge it gets in some kind of
loop where it keeps entering and leaving the frame. You can also cause
this to happen by entering the widget from the bottom and slowly moving
down. However it doesn't happen if you enter from the left or the top.

Here's the code, boiled down to the basic components that seem to
affect it in some way. Is there something I'm supposed to do in order
to prevent this from happening?

Thanks,
Marc

from Tkinter import *

class Gui:
	def __init__(self, master):
		master.geometry("200x100")
		btn = Widget(master)

class Widget:
	def __init__(self, master):
		self.master = master
		self.buildFrame()
		self.buildWidget()

	def buildFrame(self):
		self.f = Frame(self.master, height=32, width=32, relief=RIDGE,
borderwidth=2)
		self.f.place(relx=.5,rely=.5)
		self.f.bind( '<Enter>', self.enterFrame )
		self.f.bind( '<Leave>', self.leaveFrame )

	def buildWidget(self):
    		self.b = Button(self.f, text="Sure!")
    		self.b.pack(fill=BOTH, expand=1)

	def enterFrame(self, event):
		self.f.configure(cursor = 'sb_h_double_arrow')

	def leaveFrame(self, event):
		self.f.configure(cursor = '' )
		
root = Tk()
ent = Gui(root)
root.mainloop()




More information about the Python-list mailing list