472,982 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

Tkinter custom drawing

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
7 2259
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
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
>
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
from Tkinter import Invisiblecanvas

?

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

Xavier

Jun 8 '07 #5
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthew Wilson | last post by:
Hi- I've been goofing off with some basic recursive landscape generating stuff, drawing the output to a tk window. You can run the program like so: from pts import * >>> draw(5) #will...
2
by: Krzysztof Szynter | last post by:
Hi all Like i said, i'am back. With another problem of course. This is my code: ---BEGIN win=Tkinter.Tk() can=Tkinter.Canvas(win,width=500,height=500,background='blue') can.pack()
8
by: Erik Johnson | last post by:
I am looking for some input on GUI libraries. I want to build a Python-driven GUI, but don't really understand the playing field very well. I have generally heard good things about wxPython. I...
0
by: John Fouhy | last post by:
Hi all, I have been attempting to change the title bar icon of my Tkinter applications in Windows XP. Chasing round in google, I discovered: - This is a common difficulty. - There aren't any...
3
by: phil | last post by:
Using Tkinter Canvas to teach High School Geometry with A LOT of success. My drawing gets very slow after a lot of actions. For instance I have created code to rotate a set of objects about a...
11
by: William Gill | last post by:
I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep references to them in a 2 dimensional list ( rBtns ). It works fine, and I can even make it so only one button per column can be...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.