473,397 Members | 2,056 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,397 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 4122
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.