Skip to content

Instantly share code, notes, and snippets.

@FredrikAugust
Last active August 29, 2015 14:15
Show Gist options
  • Save FredrikAugust/d3e6022b229da235f04b to your computer and use it in GitHub Desktop.
Save FredrikAugust/d3e6022b229da235f04b to your computer and use it in GitHub Desktop.
Tinkering with Tkinter
from Tkinter import *
class MyApp:
def callback(self):
print self.inputValue.get()
def key(self, event):
# print "debug: pressed char {}".format(repr(event.char))
if event.char == "\r":
self.myParent.destroy()
# print "debug: close"
def __init__(self, parent):
self.heading = Label(text="hoi wereld")
self.heading.pack()
self.myParent = parent
self.container = Frame(parent)
self.container.pack()
self.inputValue = StringVar()
self.input = Entry(parent, textvariable=self.inputValue)
self.input.pack()
self.input.bind("<Key>", self.key)
self.input.focus()
self.getInputButton = Button(self.container, text="Print Input", background="white", height=4, width=16, command=self.callback)
self.getInputButton.pack(side=LEFT)
root = Tk()
myapp = MyApp(root)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment