Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_quick_ref_table_for_binds.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 Tkinter Module
- Bind Cheat Sheet
- A summary of the most common events with some keypress names explained: --
- <Button-1>
- Button 1 is the leftmost button, button 2 is the middle button
- (where available), and button 3 the rightmost button.
- .
- <Button-1>, <ButtonPress-1>, and <1> are all synonyms.
- For mouse wheel support under Linux, use Button-4 (scroll up)
- and Button-5 (scroll down)
- <B1-Motion>
- The mouse is moved, with mouse button 1 being held down (use B2 for
- the middle button, B3 for the right button).
- <ButtonRelease-1>
- Button 1 was released. This is probably a better choice in most cases
- than the Button event, because if the user accidentally presses the
- button, they can move the mouse off the widget to avoid setting off
- the event.
- <Double-Button-1>
- Button 1 was double clicked. You can use Double or Triple as prefixes.
- <Enter>
- The mouse pointer entered the widget (this event doesn't mean that
- the user pressed the Enter key!).
- <Leave>
- The mouse pointer left the widget.
- <FocusIn>
- Keyboard focus was moved to this widget, or to a child of this widget.
- <FocusOut>
- Keyboard focus was moved from this widget to another widget.
- <Configure>
- The widget changed size (or location, on some platforms). The new
- size is provided in the width and height attributes of the event
- object passed to the callback.
- <Activate>
- A widget is changing from being inactive to being active. This refers
- to changes in the state option of a widget such as a button changing
- from inactive (grayed out) to active.
- <Motion>
- The user moved the mouse pointer entirely within a widget.
- <!...>
- <Return>
- The user pressed the Enter key. For an ordinary 102-key PC-style
- keyboard, the special keys are Cancel (the Break key), BackSpace, Tab,
- Return(the Enter key), Shift_L (any Shift key), Control_L (any Control
- key), Alt_L (any Alt key), Pause, Caps_Lock, Escape, Prior (Page Up),
- Next (Page Down), End, Home, Left, Up, Right, Down, Print, Insert,
- Delete, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Num_Lock,
- and Scroll_Lock.
- <Key>
- The user pressed any key. The key is provided in the char member of
- the event object passed to the callback (this is an empty string for
- special keys).
- <a>
- The user typed an "a". Most printable characters can be used as is.
- The exceptions are space (<space>) and less than (<less>). Note that 1
- is a keyboard binding, while <1> is a button binding.
- <Shift-Up>
- The user pressed the Up arrow, while holding the Shift key pressed.
- You can use prefixes like Alt, Shift, and Control.
- <Deactivate>
- A widget is changing from being active to being inactive. This refers
- to changes in the state option of a widget such as a radiobutton
- changing from active to inactive (grayed out).
- <Destroy>
- A widget is being destroyed.
- <Expose>
- This event occurs whenever at least some part of your application or
- widget becomes visible after having been covered up by another window.
- <KeyRelease>
- The user let up on a key.
- <Map>
- A widget is being mapped, that is, made visible in the application.
- This will happen, for example, when you call the widget's .grid()
- method.
- '''.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('--'):
- value = value[:-2]
- 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