Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_table_chart.py
- import Tkinter as tk
- from PIL import Image, ImageTk
- VALUES = '''
- container ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
- anchor ? - ? - - - ? - - ? - ? - - -
- cursor ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
- font ? - ? ? ? - ? ? ? ? - ? ? ? ?
- bitmap ? - ? - - - ? - - - - ? - - -
- justify ? - ? ? ? - ? - ? ? - ? - - ?
- image ? - ? - - - ? - - - - ? - - -
- width ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
- height ? ? ? ? - ? ? ? ? - ? ? - ? -
- foreground ? - ? ? ? - ? ? ? ? - ? ? ? ?
- background ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
- padx ? - ? - - ? ? ? - ? - ? - ? -
- pady ? - ? - - ? ? ? - ? - ? - ? -
- relief ? ? ? - ? ? ? ? ? ? ? ? ? ? ?
- text ? - ? - ? - ? ? - ? - ? - - ?
- state ? ? ? ? ? - ? - ? - - ? ? ? ?
- takefocus ? ? ? ? ? ? ? ? ? ? - ? ? ? ?
- highlightcolor ? ? ? - ? ? ? ? ? ? - ? ? ? ?
- highlightbackground ? ? ? - ? ? ? ? ? ? - ? ? ? ?
- command ? - ? - - - - - - - - ? ? - ?
- length - - - - - - - - - - - - ? - -
- '''.split()
- '''
- 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
- '''
- tbitmap = '''
- ................
- .......XX.......
- .....XXXXXX.....
- ...XXXXXXXXXX...
- ...XXXXXXXXXX...
- ..XXXX....XXXX..
- ..XXX......XXX..
- .XXXX......XXXX.
- .XXXX......XXXX.
- ..XXX......XXX..
- ..XXXX....XXXX..
- ...XXXXXXXXXX...
- ...XXXXXXXXXX...
- .....XXXXXX.....
- .......XX.......
- ................
- '''.strip()
- tbitmap = list(tbitmap)
- HEADINGS = "Button Canvas Checkbutton Combobox Entry Frame Label LabelFrame Listbox Message PanedWindow Radiobutton Scale Text Spinbox".split()
- def TableChart():
- MAX_COLUMNS = len(HEADINGS)
- FONT_SIZE = 10
- subject = 'Properties of Tkinter Controls'
- r = 0
- label = tk.Label(root, text=' '+subject, anchor='w', bg='#00ff00',
- font=("Arial", FONT_SIZE+10, "bold"))
- label.grid(row=r, columnspan=MAX_COLUMNS+1, sticky="ew")
- r = 1
- c = 0
- for heading in ['']+HEADINGS:
- label = tk.Label(root, text=heading+' ', bg='#00cc00',
- font=("Arial", FONT_SIZE+2, "bold"))
- label.grid(row=r, column=c, sticky="ew")
- c += 1
- c = 0
- r = 2
- for value in VALUES:
- bgc=('#ffffff','#dddddd')[r%2]
- if value == '?':
- label = tk.Label(root, image=imgTk, anchor='w', bg=bgc)
- else:
- label = tk.Label(root, text=' '+value+' ', anchor='w', bg=bgc,
- font=("Arial", FONT_SIZE))
- label.grid(row=r, column=c, sticky="news")
- c += 1
- if c > MAX_COLUMNS:
- c = 0
- r += 1
- 0
- root = tk.Tk()
- root.title("Table Chart")
- wp=16
- hp=16
- rgb_colors = [(200,200,0,255) if z == 'X' else (0,0,0,0) for z in tbitmap]
- img = Image.new('RGBA', (wp+1,hp))
- img.putdata(rgb_colors)
- imgTk = ImageTk.PhotoImage(img)
- TableChart()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement