user interface - How to display a value from children window to parent window in python tkinter? -
i have parent window text , button. on clicking button in parent window child window opens contains entry box , button. when enter in entry box of child window , click submit of child window data entered in entry box of child window should appear in text box of parent window, how can this? code below.
from tkinter import * class application(frame): def __init__(self, master): super(application,self).__init__(master) self.grid() self.create_widgets() def create_widgets(self): self.t1=text(self,width=10,height=2) self.t1.grid(row=1,column=1) self.b1=button(self,text="create",command=self.onclick) self.b1.grid(row=2,column=1) def onclick(self): self.top = toplevel() self.top.title("title") self.top.geometry("300x150+30+30") self.top.transient(self) self.appc=demo(self.top) class demo: def __init__(self, master): self.master = master self.frame = frame(self.master) self.widget() def widget(self): self.e1=entry(self.master) self.e1.grid(row=1,column=1) self.b1=button(self.master,text="submit",command=self.onsubmit) self.b1.grid(row=2,column=1) def onsubmit(self): self.value=self.e1.get() print(self.value) root=tk() app=application(root) app.mainloop()`
you have pass reference of text
widget child window via constructor. after have full control of widget in demo
class. in onsubmit
method use insert
method:
from tkinter import * class application(frame, object): def __init__(self, master): super(application, self).\ __init__(master) self.grid() self.create_widgets() def create_widgets(self): self.t1=text(self,width=10,height=2) self.t1.grid(row=1,column=1) self.b1=button(self,text="create",command=self.onclick) self.b1.grid(row=2,column=1) def onclick(self): self.top = toplevel() self.top.title("title") self.top.geometry("300x150+30+30") self.top.transient(self) self.appc=demo(self.top, self.t1) class demo(object): def __init__(self, master, t1): self.master = master self.frame = frame(self.master) self.t1 = t1 self.widget() def widget(self): self.e1=entry(self.master) self.e1.grid(row=1,column=1) self.b1=button(self.master,text="submit",command=self.onsubmit) self.b1.grid(row=2,column=1) def onsubmit(self): self.t1.insert(insert, self.e1.get()) root=tk() app=application(root) app.mainloop()
Comments
Post a Comment