Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from MonitorModule import Monitor
- Monitor.write("xyz")
- import Tkinter
- class Monitor_non_classmothod_way(object):
- def __init__(self):
- self.mw = Tkinter.Tk()
- self.mw.title("Messages by NeuronSimulation")
- self.text = Tkinter.Text(self.mw, width = 80, height = 30)
- self.text.pack()
- self.mw.protocol(name="WM_DELETE_WINDOW", func=self.handler)
- self.is_mw = True
- def write(self, s):
- if self.is_mw:
- self.text.insert(Tkinter.END, str(s) + "n")
- else:
- print str(s)
- def handler(self):
- self.is_mw = False
- self.mw.quit()
- self.mw.destroy()
- class Monitor(object):
- @classmethod
- def write(cls, s):
- if cls.is_mw:
- cls.text.insert(Tkinter.END, str(s) + "n")
- else:
- print str(s)
- @classmethod
- def handler(cls):
- cls.is_mw = False
- cls.mw.quit()
- cls.mw.destroy()
- mw = Tkinter.Tk()
- mw.title("Messages by NeuronSimulation")
- text = Tkinter.Text(mw, width = 80, height = 30)
- text.pack()
- mw.protocol(name="WM_DELETE_WINDOW", func=handler)
- close = handler
- is_mw = True
- a = Monitor_non_classmothod_way()
- a.write("Hello Monitor one!")
- # click the close button: it works
- b = Monitor()
- Monitor.write("Hello Monitor two!")
- # click the close button: it DOESN'T work, BUT:
- # >>> Monitor.close()
- # works...
- import Tkinter
- class Monitor(object):
- def __init__(self):
- self.mw = Tkinter.Tk()
- self.mw.title("Messages by NeuronSimulation")
- self.text = Tkinter.Text(self.mw, width = 80, height = 30)
- self.text.pack()
- self.mw.protocol(name="WM_DELETE_WINDOW", func=self.handler)
- self.is_mw = True
- def write(self, s):
- if self.is_mw:
- self.text.insert(Tkinter.END, str(s) + "n")
- else:
- print str(s)
- def handler(self):
- self.is_mw = False
- self.mw.quit()
- self.mw.destroy()
- monitor = Monitor()
- from monitor import monitor
- monitor.write("Foo")
Add Comment
Please, Sign In to add comment