I'll be short. I created a tkinter GUI, which I need to call as an object or a window that appears on button click. code is:
class Test(Frame):
def __init__(self,master = None):
Frame.__init__(self, master)
self.master = master
self.win()
def win(self):
self.pack()
self.label = Label(self, text="hello World!").pack()
self.quit = Button(self, text= "quit", command = self.master.destroy).pack()
the code works fine when I call the class in the same file. ie, by adding
root=Tk()
Test()
but I want it to be called at a button click, but outside in other gui.
what I tried:
1) applying the same root = Tk()
as it is.
2) calling it in a class as object by: self.test = Test() and applying command self.test.win in the button.
Problem:'module' object is not callable.
code of other gui, where I want the button to call Test class and show gui of that class:
import Test
class Wtf(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.btn()
self.test = Test()
def btn(self):
self.pack()
self.test = Test()
self.btn = Button(self, text = "Call", command = self.test.win).pack()
root=Tk()
app = Wtf(root)
Thanks in advance. Hope I defined as much as required.
for those who did not understand:all i'm trying to here is to link the class data to the button 'btn', so that when I press the button I could get the class Test gui displayed either in the same window root or a different window.
please note: i'm a newbie at python and this program might not make sence to you, but all i'm trying here is to call the class Test on a buttonclick of 'btn'.