Advertisement
here2share

# Tk_quick_ref_table.py

Jan 25th, 2021 (edited)
2,431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.07 KB | None | 0 0
  1. # Tk_quick_ref_table.py
  2.  
  3. import Tkinter as tk
  4. from PIL import Image, ImageTk
  5.  
  6. '''
  7. from tkFileDialog import askopenfilename
  8. img_data = askopenfilename(filetypes=[('png files', '.png')]) # needs to be placed after pack()
  9.  
  10. image = Image.open(img_data)
  11. w,h = image.size
  12. img = Image.new('RGBA', (w,h))
  13. rgb = image.convert("RGBA")
  14. p = list(rgb.getdata())
  15.  
  16. for y in range(h):
  17.     s = ''
  18.     for x in range(w):
  19.         t = p.pop()
  20.         if sum(t) > 80:
  21.             s += 'X'
  22.         else:
  23.             s += '.'
  24.     print s
  25. '''
  26.  
  27. VALUES = '''
  28. Python Turtle Module
  29. Cheat Sheet
  30.  
  31.  
  32. Turtle Pen --
  33.  
  34. turtle.up()
  35. Sets the pen state to be up (for no drawing).
  36.  
  37. turtle.down()
  38. Sets the pen state to be down (for drawing).
  39.  
  40. turtle.color(r,g,b)
  41. * See Below
  42.  
  43. turtle.color(s)
  44. Sets the color that the pen will draw until the color is
  45. changed. It takes either...
  46. 1. three arguments, each a floating point number between
  47. 0.0 - 1.0, where the first the amount of red, the second is
  48. the amount of green, and the third is the amount of blue
  49. 2. a "color string" the name of a TK color (e.g., "black",
  50. "red", "blue", ...)
  51.  
  52. <!...>
  53.  
  54. turtle.begin_fill()
  55. * See Below
  56.  
  57. turtle.end_fill()
  58. To fill a figure, use turtle.begin_fill() before you start
  59. drawing the figure. Draw the figure. Then execute
  60. turtle.end_fill(). The figure drawn between the two fill
  61. commands will be filled with the present color setting.
  62.  
  63. turtle.hideturtle()
  64. * See Below
  65.  
  66. turtle.showturtle()
  67. Sets the state to hide / show the turtle. When shown, you
  68. see it as a small arrowhead pointed in the direction of the
  69. heading.
  70. The default pen color is "black".
  71.  
  72.  
  73. Turtle Draw --
  74.  
  75. turtle.right(degrees)
  76. Turns the direction that the turtle is facing right
  77. (clockwise) by the amount indicated (in degrees).
  78.  
  79. turtle.left(degrees)
  80. Turns the direction that the turtle is facing left
  81. (counterclockwise) by the amount indicated (in degrees).
  82.  
  83. turtle.forward(distance)
  84. Moves the turtle forward (in the direction the turtle is
  85. facing) the distance indicated (in pixels).
  86. Draws a line if the pen is down, not if the pen is up.
  87.  
  88. turtle.backward(distance)
  89. Moves the turtle backward (in the direction opposite to
  90. how the turtle is facing) the distance indicated
  91. (in pixels).
  92. Draws a line if the pen is down, not if the pen is up.
  93.  
  94. <!...>
  95.  
  96. turtle.setheading(angle)
  97. Sets the orientation of the turtle to angle. Here are some
  98. common directions in degrees:
  99. 0 (east)
  100. 90 (north)
  101. 180 (west)
  102. 270 (south)
  103.  
  104. turtle.goto(x,y)
  105. Moves the turtle to the specified coordinates, drawing a
  106. straight line to the destination (x,y) if the pen is down,
  107. and not drawing if the pen is up.
  108.  
  109. turtle.circle(radius)
  110. Draws a circle of the indicated radius. The turtle draws the
  111. circle tangent to the direction the turtle is facing.
  112.  
  113.  
  114. Turtle other --
  115.  
  116. turtle.xcor(), turtle.ycor()
  117. Returns the x - coordinate / y - coordinate of the current
  118. pen position.
  119.  
  120. <!...>
  121.  
  122. turtle.bye()
  123. Close the turtle drawing window
  124. '''.strip().split('\n\n')
  125.  
  126. TITLE = VALUES.pop(0).splitlines()
  127.  
  128. def TableChart():
  129.  
  130.     MAX_COLUMNS = 5
  131.     FONT_SIZE = 11
  132.     subject = ' -- '.join(TITLE)
  133.     first = 1
  134.    
  135.     def spc(t,x=1):
  136.         return '  '*x+t
  137.  
  138.     r = 0
  139.     label = tk.Label(root, text=spc(subject), anchor='w', bg='#00ff00',
  140.                      font=("Arial", FONT_SIZE+10, "bold"))
  141.     label.grid(row=r, columnspan=MAX_COLUMNS, sticky="ew")
  142.    
  143.     ccc = 0
  144.     r += 1
  145.     for value in VALUES:
  146.         c = ccc
  147.         if value.strip().endswith('--'):
  148.             section = 0
  149.             first = 1
  150.             ccc = c = 0
  151.             label = tk.Label(root, image=imgTk, bg='#ffffff', anchor='s',
  152.                                 compound="top",
  153.                                 font=("Arial", FONT_SIZE+2, "bold"))
  154.             label.grid(row=r, column=c, columnspan=5, sticky="new")
  155.             r += 1
  156.             label = tk.Label(root, image=imgTk, text=value, height=18,
  157.                                 fg='#ffffff', bg='#00cc00', compound="top",
  158.                                 anchor='s',
  159.                                 font=("Arial", FONT_SIZE+2, "bold"))
  160.             label.grid(row=r, column=c, columnspan=5, sticky="new")
  161.             r += 1
  162.             rrr = r
  163.         elif value.startswith('<!...>'):
  164.             section = 0
  165.             ccc = 3
  166.             r = rrr
  167.         else:
  168.             bgc=('#ffffff','#dddddd')[section%2]
  169.             section += 1
  170.             value = value.split('\n')
  171.             key = value.pop(0)
  172.             label = tk.Label(root, text=spc(key), anchor='w', bg=bgc,
  173.                                  font=("Arial", FONT_SIZE, "bold"))
  174.             label.grid(row=r, column=c, sticky="news")
  175.             c += 1
  176.             blank = 0
  177.             for key in value:
  178.                 if blank and first:
  179.                     label = tk.Label(root, text=' ', anchor='w', bg=bgc)
  180.                     label.grid(row=r, column=c-1, sticky="news")
  181.                 label = tk.Label(root, text=spc(key), anchor='w', bg=bgc,
  182.                                  font=("Arial", FONT_SIZE, "italic"))
  183.                 label.grid(row=r, column=c, sticky="news", ipadx=8)
  184.                 label = tk.Label(root, text='  ', anchor='w', bg='#ffffff')
  185.                 label.grid(row=r, column=2, sticky="news")
  186.                 r += 1
  187.                 blank = 1
  188.  
  189.     r += 1
  190.     label = tk.Label(root, image=imgTk, height=9, bg='#ffffff',
  191.                         font=("Arial", FONT_SIZE+2, "bold"))
  192.     label.grid(row=r, column=c, columnspan=2, sticky="new")
  193. 0
  194. root = tk.Tk()
  195. root.title(' '.join(TITLE))
  196. root.configure(background='white')
  197.  
  198. img = Image.new('RGB', (1,1))
  199. img.putdata([(0,0,0)])
  200. imgTk = ImageTk.PhotoImage(img)
  201.  
  202. TableChart()
  203.  
  204. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement