By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

Tkinter custom drawing

P: n/a
Hello everyone,

I am wondering if there is a way to use custom drawing in Tkinter.
I've been using it for few months, and all I know about custom drawing
is to draw directly on a Canvas with such methods as "create_line",
"create_rectangle", etc.

Now, the problem, is that I have already plenty of widgets on my
screen. I just want to draw over them, which is a bit difficult in my
comprehension of things.

My perfect solution was to put temporary invisible Canvas when I want
do use draw methods, but such thing doesn't exist (as far as I could
search in this community's posts).

Anyone have a clue ?

Thanks,
Xavier Berard

Jun 7 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Xavier Bérard wrote:
>
Now, the problem, is that I have already plenty of widgets on my
screen. I just want to draw over them, which is a bit difficult in my
comprehension of things.
What are you trying to achieve by "drawing over" widgets?

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
Jun 7 '07 #2

P: n/a
Xavier Bérard wrote:
Hello everyone,

I am wondering if there is a way to use custom drawing in Tkinter.
I've been using it for few months, and all I know about custom drawing
is to draw directly on a Canvas with such methods as "create_line",
"create_rectangle", etc.

Now, the problem, is that I have already plenty of widgets on my
screen. I just want to draw over them, which is a bit difficult in my
comprehension of things.

My perfect solution was to put temporary invisible Canvas when I want
do use draw methods, but such thing doesn't exist (as far as I could
search in this community's posts).

Anyone have a clue ?

Thanks,
Xavier Berard
Are you sure you are spelling it right? The C is not capitalized:

from Tkinter import Invisiblecanvas

etc.

James
Jun 7 '07 #3

P: n/a
>
Now, the problem, is that I have already plenty of widgets on my
screen. I just want to draw over them, which is a bit difficult in my
comprehension of things.

What are you trying to achieve by "drawing over" widgets?

Want I want to do is a sort of GUI builder for Tkinter. I already
finished a rough version, but for now I'm making a lighter version of
this project. So, my intent, is to create a widget under the widget.
While dragging the mouse, I want to see this rectangle that defines
the boundaries of the new widget I'm creating.

Sorry for being unclear.

Jun 8 '07 #4

P: n/a
from Tkinter import Invisiblecanvas

?

The whole web never mentions this Invisiblecanvas.
Do you have anything alike to share ? ;)

Xavier

Jun 8 '07 #5

P: n/a
Xavier Bérard wrote:
>>from Tkinter import Invisiblecanvas


?

The whole web never mentions this Invisiblecanvas.
Do you have anything alike to share ? ;)

Xavier
I figured that if you were sincere, you'd call me on this one.

Jun 8 '07 #6

P: n/a
Xavier Bérard wrote:
>>>Now, the problem, is that I have already plenty of widgets on my
screen. I just want to draw over them, which is a bit difficult in my
comprehension of things.

What are you trying to achieve by "drawing over" widgets?

Want I want to do is a sort of GUI builder for Tkinter. I already
finished a rough version, but for now I'm making a lighter version of
this project. So, my intent, is to create a widget under the widget.
While dragging the mouse, I want to see this rectangle that defines
the boundaries of the new widget I'm creating.

Sorry for being unclear.
You may want to look into the place() method. The python mega widgets
(PMW) has a PanedWidget that implements this smoothly. You may want to
emulate that approach:
#! /usr/bin/env python

from Tkinter import *

def button_pressed(e):
moved = e.widget
moved.move_pending = True
moved['cursor'] = 'hand1'
moved.press_x = e.x
moved.press_y = e.y

def button_moved(e):
moved = e.widget
if moved.move_pending:
moved.after_idle(lambda e=e: _button_moved(e))
moved.move_pending = False

def _button_moved(e):
moved = e.widget
delta_x = e.x - moved.press_x
delta_y = e.y - moved.press_y
size, wx, wy = moved.winfo_geometry().split('+')
new_x = int(wx) + delta_x
new_y = int(wy) + delta_y
moved.place(x=new_x, y=new_y)
moved.update_idletasks()
moved.move_pending = True

def button_up(e):
e.widget['cursor'] = ''

def register(widget):
widget.bind('<ButtonPress-3>', button_pressed)
widget.bind('<B3-Motion>', button_moved)
widget.bind('<Any-ButtonRelease-3>', button_up)
widget.update_idletasks()

def test():
tk = Tk()

b = Button(tk, text='Button')
b.pack()
c = Button(tk, text='Another Button')
c.pack()
x = Label(tk, text='Drag Me', relief=RIDGE, border=1)
register(x)
x.pack()

tk.geometry('200x200')
tk.mainloop()

if __name__ == "__main__":
test()
James
Jun 8 '07 #7

P: n/a
Thank you this is nice code. I never thought of using the move_pending
method..

Still it doesn't answer my question (which I ensure is very unclear).
But do not worry, I found some way to get throught my dilemma and I
can live easily with it. Thanks for your help.

Jun 9 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.