| 1 |
from Tkinter import * |
| 2 |
import string |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
class App(Frame): |
| 7 |
def __init__(self, master=None): |
| 8 |
Frame.__init__(self, master) |
| 9 |
self.pack() |
| 10 |
|
| 11 |
self.entrythingy = Entry(self) |
| 12 |
self.entrythingy.pack() |
| 13 |
|
| 14 |
self.button = Button(self, text="Uppercase The Entry", |
| 15 |
command=self.upper) |
| 16 |
self.button.pack() |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
self.contents = StringVar() |
| 24 |
self.contents.set("this is a variable") |
| 25 |
self.entrythingy.config(textvariable=self.contents) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
self.entrythingy.bind('<Key-Return>', self.print_contents) |
| 31 |
|
| 32 |
def upper(self): |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
str = string.upper(self.contents.get()) |
| 39 |
self.contents.set(str) |
| 40 |
|
| 41 |
def print_contents(self, event): |
| 42 |
print "hi. contents of entry is now ---->", self.contents.get() |
| 43 |
|
| 44 |
root = App() |
| 45 |
root.master.title("Foo") |
| 46 |
root.mainloop() |