473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_lin e",
"create_rectang le", 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 2318
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_lin e",
"create_rectang le", 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
comprehensio n 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_pend ing = True
moved['cursor'] = 'hand1'
moved.press_x = e.x
moved.press_y = e.y

def button_moved(e) :
moved = e.widget
if moved.move_pend ing:
moved.after_idl e(lambda e=e: _button_moved(e ))
moved.move_pend ing = 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_geo metry().split(' +')
new_x = int(wx) + delta_x
new_y = int(wy) + delta_y
moved.place(x=n ew_x, y=new_y)
moved.update_id letasks()
moved.move_pend ing = True

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

def register(widget ):
widget.bind('<B uttonPress-3>', button_pressed)
widget.bind('<B 3-Motion>', button_moved)
widget.bind('<A ny-ButtonRelease-3>', button_up)
widget.update_i dletasks()

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('20 0x200')
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
5382
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 create a grid of 4 ** 5 number of colored tiles.
2
1563
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
4496
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 happen to already own John Grayson's book about Tkinter programming, so that is rather handy if I decide to use Tkinter. I have done some things slightly more involved than "Hello World" in Tkinter - I have never used wxPython. So, basically the...
0
2102
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 good answers. Eventually, I stumbled across a link to this: http://www.tcl.tk/man/tcl8.4/TkCmd/wm.htm#M18
3
2240
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 rotation point. rotate 360 degrees starts to get slow after 720 degrees its crawling.
11
7874
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 selected, by assigning each column to an intVar. In many languages a radiobutton has a property that can be directly read to see if it is selected on unselected. Tkinter radiobuttons don't seem to have any such property. Is there any way to...
2
2763
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. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid correctly from the fields on the items object of the collection, but I can't get the DataGrid to...
2
2446
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 fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I am doing it wrong, any ideas what it is? Thanks in advance
11
18150
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 ListView columns so it should be doable, thanks
0
9590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.