473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2289
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.