Tkinter own text dialog?
Can someone please tell me why this isn't working and I'm not getting the text I entered back.
class eigene_dialoge: def notiz_dialog(title): notiz = "inhalt"#o(title,"r") w_editnotiz = tk.Tk() def cancel(): w_editnotiz.destroy def ok(): w_editnotiz.destroy l_wttitle = tk.Label(w_editnotiz, text="Titel:") l_wtitle = tk.Entry(w_editnotiz) l_wtitle.insert(0,title) l_wtinhalt = tk.Label(w_editnotiz, text="Inhalt:") l_winhalt = tk.Entry(w_editnotiz) l_winhalt.insert(0,notiz.read()) l_button_save = tk.Button(w_editnotiz, text="Save" ,command=ok) l_button_cancel = tk.Button(w_editnotiz, text="Abbrechen" ,command=cancel) l_wttitle.pack() l_wtitle.pack() l_wtinhalt.pack() l_winhalt.pack() l_button_save.pack() l_button_cancel.pack() l_button_save.pack(fill="x") l_button_cancel.pack(fill="x") w_editnotiz.mainloop() return [l_wtitle.get(),l_winhalt.get()] print(eigene_dialoge.notiz_dialog("test"))
(1) Strings do not have a method read more. Inserting into the input field should therefore look like this instead:
2) At the time when you read the input fields, they no longer exist.
One solution would be another sequence of operations:
It would be even better if you were to use the traditional tkinter structure. There is only one root window for each application if you need multiple window instances, use this Frame-Widget. For building the GUI you can work object-oriented.