Guest User

Untitled

a guest
Jun 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. from MonitorModule import Monitor
  2. Monitor.write("xyz")
  3.  
  4. import Tkinter
  5. class Monitor_non_classmothod_way(object):
  6. def __init__(self):
  7. self.mw = Tkinter.Tk()
  8. self.mw.title("Messages by NeuronSimulation")
  9. self.text = Tkinter.Text(self.mw, width = 80, height = 30)
  10. self.text.pack()
  11. self.mw.protocol(name="WM_DELETE_WINDOW", func=self.handler)
  12. self.is_mw = True
  13. def write(self, s):
  14. if self.is_mw:
  15. self.text.insert(Tkinter.END, str(s) + "n")
  16. else:
  17. print str(s)
  18. def handler(self):
  19. self.is_mw = False
  20. self.mw.quit()
  21. self.mw.destroy()
  22.  
  23. class Monitor(object):
  24. @classmethod
  25. def write(cls, s):
  26. if cls.is_mw:
  27. cls.text.insert(Tkinter.END, str(s) + "n")
  28. else:
  29. print str(s)
  30. @classmethod
  31. def handler(cls):
  32. cls.is_mw = False
  33. cls.mw.quit()
  34. cls.mw.destroy()
  35. mw = Tkinter.Tk()
  36. mw.title("Messages by NeuronSimulation")
  37. text = Tkinter.Text(mw, width = 80, height = 30)
  38. text.pack()
  39. mw.protocol(name="WM_DELETE_WINDOW", func=handler)
  40. close = handler
  41. is_mw = True
  42.  
  43. a = Monitor_non_classmothod_way()
  44. a.write("Hello Monitor one!")
  45. # click the close button: it works
  46. b = Monitor()
  47. Monitor.write("Hello Monitor two!")
  48. # click the close button: it DOESN'T work, BUT:
  49. # >>> Monitor.close()
  50. # works...
  51.  
  52. import Tkinter
  53.  
  54. class Monitor(object):
  55.  
  56. def __init__(self):
  57. self.mw = Tkinter.Tk()
  58. self.mw.title("Messages by NeuronSimulation")
  59. self.text = Tkinter.Text(self.mw, width = 80, height = 30)
  60. self.text.pack()
  61. self.mw.protocol(name="WM_DELETE_WINDOW", func=self.handler)
  62. self.is_mw = True
  63.  
  64. def write(self, s):
  65. if self.is_mw:
  66. self.text.insert(Tkinter.END, str(s) + "n")
  67. else:
  68. print str(s)
  69.  
  70. def handler(self):
  71. self.is_mw = False
  72. self.mw.quit()
  73. self.mw.destroy()
  74.  
  75. monitor = Monitor()
  76.  
  77. from monitor import monitor
  78. monitor.write("Foo")
Add Comment
Please, Sign In to add comment