Я извиняюсь, у кнопки параметр command.
Код можно писать как угодно в принципе.
Например:
from tkinter import *
class MainWindow(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.top = parent if parent else self.winfo_toplevel()
self.but= Button(root, text='Event', command=self.pr)
self.but.pack()
self.l= Button(root, text = '<', command=self.fr)
self.l.pack()
def fr(self):
win = Pretty_dialog(self,relief=RAISED,bd=10,bg='lightblue',
command=self.recive, title='Very well', text='Yandex')
def pr(self):
win = Pretty_dialog(self,relief=SUNKEN,bd=10,bg='lightblue',
command=self.recive, title='Bad well', text='Google')
def recive(self, text):
self.top.title(text)
class Pretty_dialog(Toplevel):
def __init__(self, parent, command=None, title='Child', text='text', **kw):
Toplevel.__init__(self, parent, **kw)
self.command = command
self.transient(parent)
self.title(title)
self.minsize(width=400, height=200)
self.lable = Label(self, text=text)
self.lable.pack()
self.entry_val = StringVar()
Entry(self, textvariable=self.entry_val).pack()
Button(self, text='Send', command=self.send).pack()
def send(self):
if(self.command):
self.command(self.entry_val.get())
self.destroy()
root = Tk()
obj = MainWindow()
root.mainloop()