Tkinter: Clipping a canvas text item

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Otten

    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_w indow(50, 80, width=100, height=20,
    window=lbl,
    anchor=tk.NW)

    root.mainloop()

    Thanks,
    Peter
  • robin bryce

    #2
    Re: Tkinter: Clipping a canvas text item

    oops. wrong thread. apologies.

    On Sat, 2004-02-21 at 13:19, Peter Otten wrote:[color=blue]
    > 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_w indow(50, 80, width=100, height=20,
    > window=lbl,
    > anchor=tk.NW)
    >
    > root.mainloop()
    >
    > Thanks,
    > Peter[/color]


    Comment

    • robin bryce

      #3
      Re: running fastcgi on windows?

      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 "Profession al 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.extensio n -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
      FastCGIExternal Server directive.

      FastCGIExternal Server /dummy/resource/path/foo.py -host
      127.0.0.1:PORTN UM

      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] "Profession al 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/


      Comment

      • John Roth

        #4
        Re: Tkinter: Clipping a canvas text item

        "Peter Otten" <__peter__@web. de> wrote in message
        news:c17ls5$hmr $04$1@news.t-online.com...[color=blue]
        > 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_w indow(50, 80, width=100, height=20,
        > window=lbl,
        > anchor=tk.NW)
        >
        > root.mainloop()
        >
        > Thanks,
        > Peter[/color]

        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


        Comment

        • wolf

          #5
          Re: running fastcgi on windows?

          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

          Comment

          Working...