Why simpledialog doesn't work with mttkinter?

265 views Asked by At

When trying to make my simpledialog thread safe by using mttkinter, i get an error. But when using the tkinter it works perfectly. Can anyone help please. Thanks in advance.

from mttkinter import mtTkinter as tk

from mttkinter import simpledialog
#### OR ####
from mtTkinter import simpledialog

#from tkinter import simpledialog


ui = tk.Tk()

input_str = tk.simpledialog.askstring("SimpleDialog", "Enter input", parent = ui)

#input_str = simpledialog.askstring("SimpleDialog", "Enter input", parent = ui)

ImportError: cannot import name 'simpledialog' from 'mttkinter'

1

There are 1 answers

5
Leo Qi On

I'm pretty sure that mtTkinter does not have the simpledialog module. It only imports the widgets in the base Tkinter module:

Because mtTkinter.py contains the following import from Tkinter import *, you can use every Tkinter widget and variable just as you normally would.

It's possible to make Tkinter thread safe without mtTkinter, and in fact there is no need to use mtTkinter if you are using Python 3:

mtTkinter is a thread-safe wrapper around Tkinter in Python. This module is only useful for Python 2.x installations, as in Python 3 Tkinter is compiled with a flag that ensures thread-safety.

If you have to use mtTkinter, try using the Tkinter Toplevel widget and making your own dialogs without simpledialog.