Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_quick_ref_table.py
- import Tkinter as tk
- from PIL import Image, ImageTk
- '''
- from tkFileDialog import askopenfilename
- img_data = askopenfilename(filetypes=[('png files', '.png')]) # needs to be placed after pack()
- image = Image.open(img_data)
- w,h = image.size
- img = Image.new('RGBA', (w,h))
- rgb = image.convert("RGBA")
- p = list(rgb.getdata())
- for y in range(h):
- s = ''
- for x in range(w):
- t = p.pop()
- if sum(t) > 80:
- s += 'X'
- else:
- s += '.'
- print s
- '''
- VALUES = '''
- Python Turtle Module
- Cheat Sheet
- Turtle Pen --
- turtle.up()
- Sets the pen state to be up (for no drawing).
- turtle.down()
- Sets the pen state to be down (for drawing).
- turtle.color(r,g,b)
- * See Below
- turtle.color(s)
- Sets the color that the pen will draw until the color is
- changed. It takes either...
- 1. three arguments, each a floating point number between
- 0.0 - 1.0, where the first the amount of red, the second is
- the amount of green, and the third is the amount of blue
- 2. a "color string" the name of a TK color (e.g., "black",
- "red", "blue", ...)
- <!...>
- turtle.begin_fill()
- * See Below
- turtle.end_fill()
- To fill a figure, use turtle.begin_fill() before you start
- drawing the figure. Draw the figure. Then execute
- turtle.end_fill(). The figure drawn between the two fill
- commands will be filled with the present color setting.
- turtle.hideturtle()
- * See Below
- turtle.showturtle()
- Sets the state to hide / show the turtle. When shown, you
- see it as a small arrowhead pointed in the direction of the
- heading.
- The default pen color is "black".
- Turtle Draw --
- turtle.right(degrees)
- Turns the direction that the turtle is facing right
- (clockwise) by the amount indicated (in degrees).
- turtle.left(degrees)
- Turns the direction that the turtle is facing left
- (counterclockwise) by the amount indicated (in degrees).
- turtle.forward(distance)
- Moves the turtle forward (in the direction the turtle is
- facing) the distance indicated (in pixels).
- Draws a line if the pen is down, not if the pen is up.
- turtle.backward(distance)
- Moves the turtle backward (in the direction opposite to
- how the turtle is facing) the distance indicated
- (in pixels).
- Draws a line if the pen is down, not if the pen is up.
- <!...>
- turtle.setheading(angle)
- Sets the orientation of the turtle to angle. Here are some
- common directions in degrees:
- 0 (east)
- 90 (north)
- 180 (west)
- 270 (south)
- turtle.goto(x,y)
- Moves the turtle to the specified coordinates, drawing a
- straight line to the destination (x,y) if the pen is down,
- and not drawing if the pen is up.
- turtle.circle(radius)
- Draws a circle of the indicated radius. The turtle draws the
- circle tangent to the direction the turtle is facing.
- Turtle other --
- turtle.xcor(), turtle.ycor()
- Returns the x - coordinate / y - coordinate of the current
- pen position.
- <!...>
- turtle.bye()
- Close the turtle drawing window
- '''.strip().split('\n\n')
- TITLE = VALUES.pop(0).splitlines()
- def TableChart():
- MAX_COLUMNS = 5
- FONT_SIZE = 11
- subject = ' -- '.join(TITLE)
- first = 1
- def spc(t,x=1):
- return ' '*x+t
- r = 0
- label = tk.Label(root, text=spc(subject), anchor='w', bg='#00ff00',
- font=("Arial", FONT_SIZE+10, "bold"))
- label.grid(row=r, columnspan=MAX_COLUMNS, sticky="ew")
- ccc = 0
- r += 1
- for value in VALUES:
- c = ccc
- if value.strip().endswith('--'):
- section = 0
- first = 1
- ccc = c = 0
- label = tk.Label(root, image=imgTk, bg='#ffffff', anchor='s',
- compound="top",
- font=("Arial", FONT_SIZE+2, "bold"))
- label.grid(row=r, column=c, columnspan=5, sticky="new")
- r += 1
- label = tk.Label(root, image=imgTk, text=value, height=18,
- fg='#ffffff', bg='#00cc00', compound="top",
- anchor='s',
- font=("Arial", FONT_SIZE+2, "bold"))
- label.grid(row=r, column=c, columnspan=5, sticky="new")
- r += 1
- rrr = r
- elif value.startswith('<!...>'):
- section = 0
- ccc = 3
- r = rrr
- else:
- bgc=('#ffffff','#dddddd')[section%2]
- section += 1
- value = value.split('\n')
- key = value.pop(0)
- label = tk.Label(root, text=spc(key), anchor='w', bg=bgc,
- font=("Arial", FONT_SIZE, "bold"))
- label.grid(row=r, column=c, sticky="news")
- c += 1
- blank = 0
- for key in value:
- if blank and first:
- label = tk.Label(root, text=' ', anchor='w', bg=bgc)
- label.grid(row=r, column=c-1, sticky="news")
- label = tk.Label(root, text=spc(key), anchor='w', bg=bgc,
- font=("Arial", FONT_SIZE, "italic"))
- label.grid(row=r, column=c, sticky="news", ipadx=8)
- label = tk.Label(root, text=' ', anchor='w', bg='#ffffff')
- label.grid(row=r, column=2, sticky="news")
- r += 1
- blank = 1
- r += 1
- label = tk.Label(root, image=imgTk, height=9, bg='#ffffff',
- font=("Arial", FONT_SIZE+2, "bold"))
- label.grid(row=r, column=c, columnspan=2, sticky="new")
- 0
- root = tk.Tk()
- root.title(' '.join(TITLE))
- root.configure(background='white')
- img = Image.new('RGB', (1,1))
- img.putdata([(0,0,0)])
- imgTk = ImageTk.PhotoImage(img)
- TableChart()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement