Created
April 23, 2023 14:25
-
-
Save vigilantPotato/568a99ba4a5bb4b3efccc671c55d0bef to your computer and use it in GitHub Desktop.
example of a simple input dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
vigilantPotato
commented
Apr 23, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment