473,219 Members | 1,784 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,219 software developers and data experts.

Tkinter: Clipping a canvas text item

Is there a way to limit both width and height of a canvas text item?
My current workaround seems clumsy:

import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=200, bg="white")
canvas.pack()

# simulate a clipped text item - never transparent :-(
s = "The long and winding road.."
lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
canvas.create_window(50, 80, width=100, height=20,
window=lbl,
anchor=tk.NW)

root.mainloop()

Thanks,
Peter
Jul 18 '05 #1
4 4103
oops. wrong thread. apologies.

On Sat, 2004-02-21 at 13:19, Peter Otten wrote:
Is there a way to limit both width and height of a canvas text item?
My current workaround seems clumsy:

import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=200, bg="white")
canvas.pack()

# simulate a clipped text item - never transparent :-(
s = "The long and winding road.."
lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
canvas.create_window(50, 80, width=100, height=20,
window=lbl,
anchor=tk.NW)

root.mainloop()

Thanks,
Peter

Jul 18 '05 #2
wolf,

I've been working in this area recently. I'm new to it too so don't take
what I say as gospel.

apache's mod_fastcgi talks to the scripts it loads via stdin, stdout and
stderr.

It deals with three basic cases: Dynamic scripts started when the url is
first accessed, Static scripts that are started with the apache server
and external scripts which are started independently of apache.

In all cases you need to think of the scripts in question as vanilla
executables that you would run at a command prompt. The difference is
that mod_fastcgi writes the request data to the exe process standard
input and expects response data, in FastCGI format, on the standard
output.

mod_fastcgi does not care what the 'exe' is as long as it replies using
the FastCGI protocol on the standard output.

The differences in the above cases are to do with how and when the
scripts are started and by what.

In all of the above cases fcgi.py acts as a utility script for helping
you to to write python scripts that can read fastcgi request data from
the standard input and reply to that request, in fastcgi format, on the
standard output. if you had a program other than apache that talked
FastCGI then these scripts would probably be just as happy talking to it
as they would apache.

the problem with fcgi.py on windows is probably, I have not tried it on
windows, to do with os dependencies introduced by the need to open and
manipulate sockets and redirect standard output. making it windows
friendly is essentially a job of bullying it into doing things the
Windows way (but see attached file and later comments for a possible
alternative).

the _test() function in fcgi.py is the basic template for the body of
your fastcgi friendly python script. a typical fast cgi friendly python
script would look like:

#!/path/to/python
import fcgi

# something modelled on the body of fcgi._test()

# end

I spent longer than I should have with this all broken simply because I
forgot that statements like print "why am I broken" write to the
standard output.

The best place for information about configuring Apache to use fastcgi
is proly the fastcgi site [1] and you should verify my assertions there.
Also a book that helped me loads was "Professional Apache 2.0" by Peter
Wainwright [2].

options for the dynamic case:

# turn on cgi
Options +ExecCGI

# turn on fastcgi for url's ending in .py - can be any extension you
like.

AddHandler fastcgi-script .py

# restart now and again to counter memory leaks and limmit the number of
processes

FastCgiConfig -restart -restart-delay 10 -maxprocesses 5

are about the only options you need - assuming you've loaded mod_fastcgi

options for the static case:

FastCgiServer /path/to/your/script.extension -init-start-delay 5
replaces FastCgiConfig
I recently modified the fcgi.py script you referenced to get it to work
with the Twisted framework [3]. This let me bridge from an apache server
to a remote Twisted web server using the the third, external server
model. After I did this I posted my changes [4] to fcgi.py to the
Twisted mailing list only to have someone, very kindly, point out I
could have got the same job done much easier with mod_proxy. I'm still
not clear if FastCGI offers any advantages over mod_proxy in this case.

The modifications remove the portions of fcgi.py that are dependent os
services and instead rely on the Twisted framework for this. I have not
run my app on a windows box since I introduced this feature but it was
running on windows before this. I can see no reason why it won't still
work.

This is the FastCGI case where apache is configured using the
FastCGIExternalServer directive.

FastCGIExternalServer /dummy/resource/path/foo.py -host
127.0.0.1:PORTNUM

you can replace the ip address with a remote one or do
-RPORTNUM:127.0.0.1:PORTNUM style tricks with ssh (PuTTY to windows
users[5]).
Hope this helps & best of luck.

Robin

[1] http://www.fastcgi.com/mod_fastcgi/d...d_fastcgi.html
[2] "Professional Apache 2.0"by Peter Wainwright. http://www.wrox.com/
[3] http://www.twistedmatrix.com/
[4] The version of fcgi.py with my mods is atatched. I've been in touch
with Robin Dunn and he's fine about me contributing my mods provided the
original copyright and boiler plate is left intact. Please note that
Robin Dunn has _not_ in anyway suggested that my mods are beneficial in
anyway.
[5] http://www.chiark.greenend.org.uk/~sgtatham/putty/
Jul 18 '05 #3
"Peter Otten" <__*******@web.de> wrote in message
news:c1*************@news.t-online.com...
Is there a way to limit both width and height of a canvas text item?
My current workaround seems clumsy:

import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=200, bg="white")
canvas.pack()

# simulate a clipped text item - never transparent :-(
s = "The long and winding road.."
lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
canvas.create_window(50, 80, width=100, height=20,
window=lbl,
anchor=tk.NW)

root.mainloop()

Thanks,
Peter


I suppose if I absolutely had to do it, I'd clip by hiding the edges
under something else. Or else I'd find another toolkit that can
do the job. Thankfully, I don't have to do it.

John Roth
Jul 18 '05 #4
robin,

thanks a lot for your answer. it helps me in
so far as i now believe it should be feasible
to get fastcgi and python running on windows.
would you mind to re-post your modified file
directly? i'm afraid the attachment didn't make
it to the list and i couldn't find it on
the twisted mailing list either.

_wolf
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
3
by: John Velman | last post by:
I want to draw a box around a short piece of text in canvas (one line text). I know how to do it if I place the text on the canvas first,then draw the box around it. Is there a way to find out...
4
by: pavel.kosina | last post by:
It seems to me that in my "again and again repainting canvas" script the rendering is slowing down as the time goes. It is visible even after 10 seconds. Any idea why? -- geon The exception...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
2
TMS
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:...
4
by: Davy | last post by:
Hi all, I have written a simple Tkinter program, that is draw a rectangle in a canvas, when I press Up key, the rectangle move up. But the program seems work not properly? My environment is...
4
by: skanemupp | last post by:
mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\elmapovic.gif') w.create_image(10, 10, image = mapq, anchor = NW) after doing this is there any possibility of getting the characteristics of...
7
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...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.