Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_form_demo.py ZZZ
- from Tkinter import *
- def everyVar():
- print 'listbox = '+str([zzz[int(z)] for z in listbox.curselection()])
- for k,v in cv.var.items():
- v=v.get()
- if v and k != 'listbox': print k,'=',v
- print
- root=Tk()
- root.geometry('420x640+500+10')
- root.title("Tkinter Form Demo")
- class Cv():
- var={}
- cv=Cv()
- widgets="cb rb listbox pop spinbox scale entry label drop button Lframe xy".split()
- for z in widgets:
- cv.var[z]=StringVar()
- def key(event):
- print "pressed", repr(event.char)
- def callback(event):
- Lframe.focus_set()
- print "clicked at", event.x, event.y
- cv.var['xy'].set((event.x, event.y))
- Lframe=LabelFrame(root, text="Click Mouse Here", width=400, height=200)
- Lframe.bind("<Key>", key)
- Lframe.bind("<Button-1>", callback)
- Lframe2=Label(Lframe, text='0, 0', textvariable=cv.var['xy'], anchor='e')
- listbox=Listbox(root, height=7, selectmode=EXTENDED)
- zzz="one two three four five".split()
- for item in zzz:
- listbox.insert(END, item)
- pop=OptionMenu(root, cv.var['drop'], *zzz)
- z=1
- rb=['']
- for item in zzz:
- rb.append(Radiobutton(root, text=item.title(), variable=cv.var['rb'], value=z))
- z+=1
- cb=Checkbutton(root, text="Checked?", variable=cv.var['cb'], onvalue="on", offvalue="off")
- entry=Entry(root, textvariable=cv.var['entry'], bg='yellow')
- label=Label(root, textvariable=cv.var['entry'])
- spinbox=Spinbox(root, from_=1, to=12, textvariable=cv.var['spinbox'])
- scale= Scale(root, from_=0, to=100, variable=cv.var['scale'])
- button=Button(root, text="Click To Print Contents Of Array", command=everyVar)
- for widget in (cb, rb[1], rb[2], rb[3], listbox, pop, spinbox, scale, entry, label, button):
- widget.pack(anchor="w", padx=10)
- Lframe.pack(padx=10, pady=10)
- Lframe.pack_propagate(0)
- Lframe2.pack(side=TOP, anchor=E, padx=10)
- default='''
- scale
- 27
- drop
- three
- rb
- 2
- cb
- on
- spinbox
- 9
- entry
- Hello Python World!
- '''[1:-1].split('\n\n')
- for z in default:
- b,v=z.split('\n')
- cv.var[b].set(v)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement