1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
#
#
import Tkinter
def OnButtonClick():
root.labelVariable.set(root.entryVariable.get()+
" (You clicked the button)" )
root.entry.focus_set()
root.entry.selection_range(0, Tkinter.END)
def OnPressEnter(root,event):
root.labelVariable.set(root.entryVariable.get()+
" (You pressed ENTER)" )
root.entry.focus_set()
root.entry.selection_range(0, Tkinter.END)
root = Tkinter.Tk()
root.grid()
root.entryVariable = Tkinter.StringVar()
root.entry = Tkinter.Entry(root, textvariable=root.entryVariable)
root.entry.grid(column=0, row=0, sticky='EW')
root.entry.bind("<Return>", OnPressEnter)
root.entryVariable.set("Enter text here.")
button = Tkinter.Button(root, text="Click me !", command=OnButtonClick)
button.grid(column=1,row=0)
root.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(root, textvariable=root.labelVariable,
anchor="w", fg="white", bg="blue")
label.grid(column=0, row=1, columnspan=2, sticky='EW')
root.labelVariable.set("Hello !")
root.grid_columnconfigure(0, weight=1)
root.resizable(True, False)
root.update()
root.geometry(root.geometry())
root.entry.focus_set()
root.entry.selection_range(0, Tkinter.END)
root.title('my application')
root.mainloop() |
Partager