I have written a reasonably clean way to perform coordinate transformations
on a polygon, but Tkinter Canvas is not being particularly cooperative. The
following program has been distilled down to a minimum and generates a
traceback (see below) when it runs.
It appears that the create_polygon( ) method is more versatile than the
coords() method.
Could someone can suggest a way to have the list comprehension not generate
tuples, that would probably create a coordinate list acceptable to coords()?
Thanks,
Dave Harris
# cantest.py - canvas test program
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
c = Canvas(frame, width=300, height=300)
c.pack()
outline1 = [(100, 0), (200, 50), (150, 150)]
p1 = c.create_polygo n(outline1, fill='', outline='black' )
p2 = c.create_polygo n(outline1, fill='', outline='red')
outline2 = [(x+10, y+20) for (x, y) in outline1]
c.coords(p2, outline2)
root = Tk()
app = App(root)
root.mainloop()
Traceback (most recent call last):
File "cantest.py ", line 24, in ?
app = App(root)
File "cantest.py ", line 20, in __init__
c.coords(p2, outline2)
File "C:\PYTHON23\Li b\lib-tk\Tkinter.py", line 2039, in coords
self.tk.splitli st(
_tkinter.TclErr or: bad screen distance "170)]" 1 5362
Dave Harris wrote: I have written a reasonably clean way to perform coordinate transformations on a polygon, but Tkinter Canvas is not being particularly cooperative. The following program has been distilled down to a minimum and generates a traceback (see below) when it runs.
It appears that the create_polygon( ) method is more versatile than the coords() method.
Could someone can suggest a way to have the list comprehension not generate tuples, that would probably create a coordinate list acceptable to coords()?
You can explicitly flatten the list:
import Tkinter
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
c = Canvas(frame, width=300, height=300)
c.pack()
outline1 = [(100, 0), (200, 50), (150, 150)]
p1 = c.create_polygo n(outline1, fill='', outline='black' )
p2 = c.create_polygo n(outline1, fill='', outline='red')
outline2 = [(x+10, y+20) for (x, y) in outline1]
c.coords(p2, Tkinter._flatte n(outline2))
root = Tk()
app = App(root)
root.mainloop()
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marc |
last post by:
Hi all,
I've been using the canvas quite a bit lately, and I am wondering if I
am just missing a quick trick somewhere.
With most canvas objects you can bind then to mouse functions and
quickly determine if you are selecting them. However, the rectangle
(and I'm sure all other objects that aren't solid) only register if
you actually hit the frame of the object, if it's transparent. If you
fill it with color then it will register...
|
by: Fuzzyman |
last post by:
Pythons internal 'pointers' system is certainly causing me a few
headaches..... When I want to copy the contents of a variable I find
it impossible to know whether I've copied the contents *or* just
created a new pointer to the original value....
For example I wanted to initialize a list of empty lists....
a=, , , , ]
I thought there has to be a *really* easy way of doing it - after a
|
by: Matthias Vodel |
last post by:
Hi all,
I want to change the beginning/end-coordinates of a canvas.line item.
Something like:
self.myCanvas.itemconfigure(item_id, coords=(x1_new, y1_new, x2_new,
y2_new))
I don't want to delete and repaint a new line item. Is this possible?
|
by: TMS |
last post by:
Schools over!!! Now its time to play.
I would like to learn how to make objects move from one location to the next on a canvas widget. For example:
from Tkinter import *
class square:
def __init__(self, canvas, xy, color, change):
self.canvas = canvas
self.id = self.canvas.create_rectangle(-10-abs(change),
|
by: Debajit Adhikary |
last post by:
I have two lists:
a =
b =
What I'd like to do is append all of the elements of b at the end of
a, so that a looks like:
a =
| |
by: friendkitty |
last post by:
Hi All,
I m a new member here.I am now writing a program that render Vertex Normals.I m now trying to implement a data structure that will best suit computing vertex normals.For that computation , my data structure should have accessed to the faces adjacent to each vertices.
first i read all vertices ,and faces from .m file into a structure.And stored in vectors.
vector<Vertex> vertices;
vector<Face> faces;
Then i render that model.No...
|
by: Peter Pearson |
last post by:
Tkinter makes it very easy to drag jpeg images around on a
canvas, but I would like to have a "target" change color when
the cursor dragging an image passes over it. I seem to be
blocked by the fact that the callbacks that might tell the
target that the mouse has entered it (<Enter>, <Any-Enter>,
even <Motion>) aren't called if the mouse's button is down.
What am I missing? Have I failed to find the right Tkinter
document? Is Tkinter...
|
by: MartinRinehart |
last post by:
I'm drawing curves on a canvas. And then redrawing, re-redrawing, ...
Are there any tools that could help me draw in something more graphic
than the eight arguments of the Bezier curve?
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |