-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialog_example.py
More file actions
38 lines (29 loc) · 1.05 KB
/
dialog_example.py
File metadata and controls
38 lines (29 loc) · 1.05 KB
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
import tkinter as tk
class CustomDialog(tk.Toplevel):
def __init__(self, parent, prompt):
tk.Toplevel.__init__(self, parent)
self.var = tk.StringVar()
self.label = tk.Label(self, text=prompt)
self.entry = tk.Entry(self, textvariable=self.var)
self.ok_button = tk.Button(self, text="OK", command=self.on_ok)
self.label.pack(side="top", fill="x")
self.entry.pack(side="top", fill="x")
self.ok_button.pack(side="right")
self.entry.bind("<Return>", self.on_ok)
def on_ok(self, event=None):
self.destroy()
def show(self, parent):
parent.withdraw()
self.entry.focus_force()
self.wait_window()
return self.var.get()
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
info = 'britt'
self.svar = CustomDialog(self, "Svar").show(parent)
if __name__ == "__main__":
root = tk.Tk()
test246 = ''
e = Example(root)
print(e.svar)