I'm trying to make a text entry dialog with Tkinter (Python 3.5) but I'm having some problems. This is my code:
class TextEntryDialog:
def __init__(self, master):
self.top = Toplevel(master)
self.textField = Entry()
self.textField.pack()
root = Tk()
ted = TextEntryDialog(root)
root.mainloop()
When I run this I get a dialog and a main window just like I want, but the problem is that when I close the dialog the main window closes as well. I would like the main window to stay open when the dialog closes, can anyone help me with this?
Add titles to windows and you see
You add Entry
to MainWindow
.
And you close MainWindow
but you think it is TextEntryDialog
.
You have to add self.top
(Toplevel
) as parent
in Entry
to put it in correct window.
self.textField = Entry(self.top)
.
from tkinter import *
class TextEntryDialog:
def __init__(self, master):
self.top = Toplevel(master)
self.top.title("TextEntryDialog")
self.textField = Entry(self.top) # parent
self.textField.pack()
root = Tk()
root.title("MainWindow")
ted = TextEntryDialog(root)
root.mainloop()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments