Thursday 1 December 2016

Canvas - Text

img_a_01

The first code shows how the text is located in the canvas:

from Tkinter import *

root = Tk()

ch, cw = 200, 200
x0, y0 =   0,   0
x1, y1 =  20,  40 
bgc    = "black"  # bgc : background colour

c1 = Canvas(root, height = ch, width = cw, bg = bgc)

c1.create_text( x1, y1, anchor = W, font= "Verdana" ,
                text = "Hey there!", fill="white"   )
c1.create_rectangle( x0, y0, x1, y1,
                     fill    = "blue",
                     outline = "cyan")
c1.pack()
root.title("Draft")
root.mainloop()
 

We must create a canvas using the "Canvas" method, also its dimensions are declared here.

c1 = Tkinter.Canvas(root, height = ch, width = cw, bg = "black")

Then we create text by using:

c1.create_text( x1, y1, anchor = W, font = "Verdana" , text = "Hey there!", fill="white")

The text will be fitted inside an invisible rectangle, but the position will refered with respect to the intersection point between the left side line of the rectangle and the line that divides the rectangle in half, and then the location of this intersection point will be fixed by (x1, y1). In this case, it's been used (x1,y1) = (20; 40) as the position of such intersection point.

(x1,y1) = (20, 40)

To show what has been explained of the intersection point, there's a graphical example that uses the drawing of a rectangle that uses the origin point (0; 0) and the point (x1, y1) as its corners.Then we could show the results in the screen by using the "pack" or "grid" methods.

img_01

The next examples have some variations.

Second code sample is:

from Tkinter import *

root    = Tk()
s       = 20
ch, cw  = 200, 200
x, y, n =  0,  90, 11
bgc     = "black"  # bgc : background colour
cr1     = "white"
cr2     = "red"
strin6  = '''Python 2.7.9
(
  default\t\t,
  Dec 10 2014\t,
  12:24:55
)'''

c1 = Canvas(root, height = ch, width = cw, bg = bgc)
c1.create_text(20, 90, anchor = W, font=("Verdana", n), text = strin6, fill="white")
c1.pack()
root.title("Dr4f7")
root.mainloop()
 
img_01

Third code sample is:

from Tkinter import *

def line(a, b, color, w):
    x0, y0, x1, y1 = a[0], a[1], b[0], b[1]
    c1.create_line(x0, y0, x1, y1, fill = color, width = w)

def txt(x, y, txt, size, colour):
    c1.create_text( x, y,
                    anchor = W,
                    font = ("Verdana", size),
                    text = txt,
                    fill = colour)

def n(a0, L, w):
    x0, y0 = a0[0], a0[1]
    x1, y1 = x0 + L, y0 + L
    dx, dy = L / 5.0, L / 5.0
    a1, b1 = [x0 - dx, y0 - dy], [x1 + dx, y1 + dy]
    a2, b2 = [a1[0], b1[1]], [b1[0], a1[1]]
    r1, r2 = "orange", "white"
    c1.create_oval(x0, y0, x1, y1, outline = r1, fill = r2, width = w)
    line(a2, b2, r1, w)
    print a2, "\n", b2

root   = Tk()
n_t1   = 14
n_t2   = 9
ch, cw = 600, 350
x0, y0 =   20, ch*0.5
bgc    = "black"  # bgc : background colour
cr1    = "white"
cr2    = "red"
a, b   = [2 * x0, ch - 20], [cw - 2 * x0, ch - 20]
c, d   = [2 * x0, ch - 30], [cw - 2 * x0, ch - 30]
e1     = [c[0] - 28, c[1] - 3]
e2     = [d[0] + 10, d[1] - 3]
title = '''
Joydrop - Breakdown
(Lyrics)
'''
lyrics = '''

And I don't hear you anymore
And I can't see you on the floor
It's like a nightmare come to life
But don't be frightened of the light

And all the days you pushed around
And all the times you lied to yourself
And all the dreams we had just might breakdown
woooo--ooo
Breakdown
woooo--ooo
And I wonder who you love, really love

You know I want you too much
You know it kills me the thought
I want to scream, I want to cry
Just to save myself just one last time

And all the days you pushed around
And all the times you lied to yourself
And all the dreams we had just might breakdown
woooo--ooo
Breakdown
woooo--ooo
And I wonder who you love, really love

And all the days you pushed around
And all the times you lied to yourself
And all the dreams we had just might breakdown
woooo--ooo
Breakdown
woooo--ooo
Breakdown
woooo--ooo
And I wonder who you love, really love
'''

c1 = Canvas(root, height = ch, width = cw, bg = bgc)
txt(x0, 1.35*x0,  title, n_t1,   "red")
txt(x0, y0, lyrics, n_t2, "white")
line(a, b, "orange", 1)
line(c, d, "orange", 1)
#--- circle symbols ---#
n(e1, 18, 2)
n(e2, 18, 2)

c1.pack()
root.title("Joydrop - Breakdown (Lyrics)")
print a, b
print c, d
root.mainloop()
 
img_01

2 comments:

  1. tell me
    i don't wanna people in my face
    fade away
    i got more to say
    let me
    all day all nigh
    all right


    Leon Bridges "bad bad news"




    Lyrics - Eilen Jewell

    James Arthur - Say You Won't Let Go - YouTube

    Machine Gun Kelly - Go For Broke (Lyric Video) ft. James Arthur ...

    SYML - Where's My Love [Official Video] - YouTube

    Machine Gun Kelly - Let You Go (Lyric Video) - YouTube

    Beck - Up All Night - YouTube

    NF - Outcast - YouTube

    Lil Skies - Nowadays ft. Landon Cube (Dir. by @_ColeBennett_) ...

    Big Boi – All Night Lyrics | Genius Lyrics


    JOHN.k – OT Lyrics | Genius Lyrics

    ReplyDelete
  2. flow patters over different bodies, like:
    - cylinder
    - prismatic rectangle

    we're supposed to base part of our work in this specific problem of some parameters inside a open channel, including vortives that may be formed along certain obstacles

    until they reach shallow water and feel the bottom, ocean waves are almost frictionless.

    Waves are created by winds, especially storms.

    Long waves - large distances between crests - travel the fastest and decay the slowest.

    Short waves decay more quickly but are still nearly frictionless.

    The pictured long waves, breaking on the beach in Narragansett, Rhode Island, might have been formed from a storm off the coast of Africa.

    The theory of ocean waves [21] is based almost entirely upon frictionless flow.

    (Photo courtesy of Ellen Emerson White.)


    [21]:
    J. N. Newman, "Marine Hydrodynamics". MIT Press, Cambridge, MA, 1977.



    * A spher of volume V in a fluid density rho is located at a point (0, L , 0) with respect to a certain coordinate system.

    In terms of this coordinate sysyem,
    (a) identify wheter each of the 6x6 added mass coeficients m_ij are zero (0), or non-zero (x) (do not work out any values )

    (b) if the sphere has generalized velocity of
    (0, U_2, 0, 0, 0, u_6), the total kinetic energy of the surrounding fluid is ______. (?)


    http://web.mit.edu/2.20/www/suppnotes/supp.pdf

    http://web.mit.edu/2.20/www/supp_notes.html

    ReplyDelete