Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created April 23, 2023 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/568a99ba4a5bb4b3efccc671c55d0bef to your computer and use it in GitHub Desktop.
Save vigilantPotato/568a99ba4a5bb4b3efccc671c55d0bef to your computer and use it in GitHub Desktop.
example of a simple input dialog
import tkinter
class InputDialog(tkinter.Toplevel):
"""
show a dialog which asks user to input something
"""
def __init__(self, root):
super().__init__(root)
self.attributes("-topmost", True)
self.title("Input information")
label = tkinter.Label(self, text="input")
label.pack()
self.entry = tkinter.Entry(self, width=30)
self.entry.pack()
ok_button = tkinter.Button(
self,
text="OK",
command=self.finished,
)
ok_button.pack()
cancel_button = tkinter.Button(
self,
text="cancel",
command=self.canceled,
)
cancel_button.pack()
self.wait_visibility()
self.grab_set()
self.wait_window()
def finished(self):
self.result = self.entry.get()
self.destroy()
def canceled(self):
self.result = None
self.destroy()
if __name__ == "__main__":
root = tkinter.Tk()
print(InputDialog(root).result)
root.mainloop()
@vigilantPotato
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment