Reputation: 3
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:
from tkinter import *
from tkinter import simpledialog
Other elements (buttons, labels etc.) in the main window work correctly. Please help.
Upvotes: 0
Views: 4650
Reputation: 11
from tkinter import simpledialog
You imported simple dialog to your module, which means you don't need the prefix:
tkinter.
Since you have the simple dialog installed. You can do this:
from tkinter import simpledialog
input = simpledialog.askstring("Title of Window", "Question")
# You don't need the Tk window if you don't want it; simple dialog will create a second window to ask the question.
Upvotes: 1