Advertisement
here2share

# Tk_quick_ref_table_for_binds.py

Feb 14th, 2021
1,689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.82 KB | None | 0 0
  1. # Tk_quick_ref_table_for_binds.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 Tkinter Module
  29. Bind Cheat Sheet
  30.  
  31. A summary of the most common events with some keypress names explained: --
  32.  
  33. <Button-1>
  34. Button 1 is the leftmost button, button 2 is the middle button
  35. (where available), and button 3 the rightmost button.
  36. .
  37. <Button-1>, <ButtonPress-1>, and <1> are all synonyms.
  38. For mouse wheel support under Linux, use Button-4 (scroll up)
  39. and Button-5 (scroll down)
  40.  
  41. <B1-Motion>
  42. The mouse is moved, with mouse button 1 being held down (use B2 for
  43. the middle button, B3 for the right button).
  44.  
  45. <ButtonRelease-1>
  46. Button 1 was released. This is probably a better choice in most cases
  47. than the Button event, because if the user accidentally presses the
  48. button, they can move the mouse off the widget to avoid setting off
  49. the event.
  50.  
  51. <Double-Button-1>
  52. Button 1 was double clicked. You can use Double or Triple as prefixes.
  53.  
  54. <Enter>
  55. The mouse pointer entered the widget (this event doesn't mean that
  56. the user pressed the Enter key!).
  57.  
  58. <Leave>
  59. The mouse pointer left the widget.
  60.  
  61. <FocusIn>
  62. Keyboard focus was moved to this widget, or to a child of this widget.
  63.  
  64. <FocusOut>
  65. Keyboard focus was moved from this widget to another widget.
  66.  
  67. <Configure>
  68. The widget changed size (or location, on some platforms). The new
  69. size is provided in the width and height attributes of the event
  70. object passed to the callback.
  71.  
  72. <Activate>
  73. A widget is changing from being inactive to being active. This refers
  74. to changes in the state option of a widget such as a button changing
  75. from inactive (grayed out) to active.
  76.  
  77. <Motion>
  78. The user moved the mouse pointer entirely within a widget.
  79.  
  80. <!...>
  81.  
  82. <Return>
  83. The user pressed the Enter key. For an ordinary 102-key PC-style
  84. keyboard, the special keys are Cancel (the Break key), BackSpace, Tab,
  85. Return(the Enter key), Shift_L (any Shift key), Control_L (any Control
  86. key), Alt_L (any Alt key), Pause, Caps_Lock, Escape, Prior (Page Up),
  87. Next (Page Down), End, Home, Left, Up, Right, Down, Print, Insert,
  88. Delete, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Num_Lock,
  89. and Scroll_Lock.
  90.  
  91. <Key>
  92. The user pressed any key. The key is provided in the char member of
  93. the event object passed to the callback (this is an empty string for
  94. special keys).
  95.  
  96. <a>
  97. The user typed an "a". Most printable characters can be used as is.
  98. The exceptions are space (<space>) and less than (<less>). Note that 1
  99. is a keyboard binding, while <1> is a button binding.
  100.  
  101. <Shift-Up>
  102. The user pressed the Up arrow, while holding the Shift key pressed.
  103. You can use prefixes like Alt, Shift, and Control.
  104.  
  105. <Deactivate>
  106. A widget is changing from being active to being inactive. This refers
  107. to changes in the state option of a widget such as a radiobutton
  108. changing from active to inactive (grayed out).
  109.  
  110. <Destroy>
  111. A widget is being destroyed.
  112.  
  113. <Expose>
  114. This event occurs whenever at least some part of your application or
  115. widget becomes visible after having been covered up by another window.
  116.  
  117. <KeyRelease>
  118. The user let up on a key.
  119.  
  120. <Map>
  121. A widget is being mapped, that is, made visible in the application.
  122. This will happen, for example, when you call the widget's .grid()
  123. method.
  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.             value = value[:-2]
  149.             section = 0
  150.             first = 1
  151.             ccc = c = 0
  152.             label = tk.Label(root, image=imgTk, bg='#ffffff', anchor='s',
  153.                                 compound="top",
  154.                                 font=("Arial", FONT_SIZE+2, "bold"))
  155.             label.grid(row=r, column=c, columnspan=5, sticky="new")
  156.             r += 1
  157.             label = tk.Label(root, image=imgTk, text=value, height=18,
  158.                                 fg='#ffffff', bg='#00cc00', compound="top",
  159.                                 anchor='s',
  160.                                 font=("Arial", FONT_SIZE+2, "bold"))
  161.             label.grid(row=r, column=c, columnspan=5, sticky="new")
  162.             r += 1
  163.             rrr = r
  164.         elif value.startswith('<!...>'):
  165.             section = 0
  166.             ccc = 3
  167.             r = rrr
  168.         else:
  169.             bgc=('#ffffff','#dddddd')[section%2]
  170.             section += 1
  171.             value = value.split('\n')
  172.             key = value.pop(0)
  173.             label = tk.Label(root, text=spc(key), anchor='w', bg=bgc,
  174.                                  font=("Arial", FONT_SIZE, "bold"))
  175.             label.grid(row=r, column=c, sticky="news")
  176.             c += 1
  177.             blank = 0
  178.             for key in value:
  179.                 if blank and first:
  180.                     label = tk.Label(root, text=' ', anchor='w', bg=bgc)
  181.                     label.grid(row=r, column=c-1, sticky="news")
  182.                 label = tk.Label(root, text=spc(key), anchor='w', bg=bgc,
  183.                                  font=("Arial", FONT_SIZE, "italic"))
  184.                 label.grid(row=r, column=c, sticky="news", ipadx=8)
  185.                 label = tk.Label(root, text='  ', anchor='w', bg='#ffffff')
  186.                 label.grid(row=r, column=2, sticky="news")
  187.                 r += 1
  188.                 blank = 1
  189.  
  190.     r += 1
  191.     label = tk.Label(root, image=imgTk, height=9, bg='#ffffff',
  192.                         font=("Arial", FONT_SIZE+2, "bold"))
  193.     label.grid(row=r, column=c, columnspan=2, sticky="new")
  194. 0
  195. root = tk.Tk()
  196. root.title(' '.join(TITLE))
  197. root.configure(background='white')
  198.  
  199. img = Image.new('RGB', (1,1))
  200. img.putdata([(0,0,0)])
  201. imgTk = ImageTk.PhotoImage(img)
  202.  
  203. TableChart()
  204.  
  205. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement