Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python tkinter simpledialog

I have a Python script which generates a GUI window with tkinter library. I’d like to make some of it’s buttons display a prompt – small window to ask the user for some number (something like in JavaScript). I tried the following command:

x = tkinter.simpledialog.askstring

But it returns an error:

NameError: name 'tkinter' is not defined

and no prompt is generated, although I have imported the library in the script’s beginning:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from tkinter import *
from tkinter import simpledialog

Other elements (buttons, labels etc.) in the main window work correctly. Please help.

>Solution :

askstring is part of tkinter.simpledialog so you might import it like so

from tkinter.simpledialog import askstring

usage example

import tkinter as tk
from tkinter.simpledialog import askstring
root = tk.Tk()
x = askstring("Title", "Prompt")
print(x)
root.mainloop()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading