0

I have to create popup dialog box which contains text field using tkinter module in Python 2(not Python 3). My other program has many Python2 modules(I have written whole code in Python 2) and so I can't go for Python 3. Here is my code which works fine in Python 3 but not in Python 2.

from tkinter import simpledialog
from tkinter import *
def s():
 print(simpledialog.askstring("hai","inp"))

root = Tk()
b = Button(root, text="popup",command=s)
b.pack()

root.geometry("400x400")
root.mainloop()

This is the error :

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1550, in __call__
    return self.func(*args)
  File "popup.py", line 4, in s
    print(simpledialog.askstring("hai","inp"))
AttributeError: 'module' object has no attribute 'askstring'

Please mention any alternatives to achieve this function in Python 2. Thank you

1 Answer 1

1

Just change

from tkinter import simpledialog
from tkinter import *

to

import tkSimpleDialog as simpledialog
from Tkinter import *
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.