Skip to content

Instantly share code, notes, and snippets.

@saltlakeryan
Created March 23, 2017 16:46
Show Gist options
  • Save saltlakeryan/e29e99243428d15d103aa94a814e9c57 to your computer and use it in GitHub Desktop.
Save saltlakeryan/e29e99243428d15d103aa94a814e9c57 to your computer and use it in GitHub Desktop.
python simple TK example
#!/usr/bin/env python
from Tkinter import *
import sys
answer = ""
def center(toplevel):
toplevel.update_idletasks()
w = toplevel.winfo_screenwidth()
h = toplevel.winfo_screenheight()
size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x'))
#x = w/2 - size[0]/2
#y = h/2 - size[1]/2
x = 1900
y = 0
toplevel.geometry("%dx%d+%d+%d" % (size + (x, y)))
class MyDialog:
def __init__(self, parent):
top = self.top = parent
Label(top, text="Value").pack()
self.e = Entry(top)
self.e.pack(padx=5)
b = Button(top, text="OK", command=self.ok)
b.pack(pady=5)
self.e.focus()
def ok(self):
global answer
answer = self.e.get()
self.top.destroy()
if len(sys.argv) >= 2:
answer = sys.argv[1]
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
root2 = Tk()
w = Label(root2, text=answer)
w.config(font=("Courier", 44))
w.pack()
center(root2)
print("HERE")
root2.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment