Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3.  
  4. class Channel(tk.Frame):
  5. def __init__(self, parent, *args, **kwargs):
  6. tk.Frame.__init__(self, parent, *args, **kwargs)
  7. self.parent = parent
  8. self.btn = tk.Button(self.parent, text = 'click me', command = self.change_green)
  9. self.btn.pack()
  10. def change_green(self):
  11. main_window.channel_1.btn.config(bg = 'green') # line 11
  12.  
  13.  
  14. class MainApplication(tk.Frame):
  15. def __init__(self, parent, *args, **kwargs):
  16. tk.Frame.__init__(self, parent, *args, **kwargs)
  17. self.parent = parent
  18. self.tab_control = ttk.Notebook(self.parent)
  19. self.tab_1 = ttk.Frame(self.tab_control)
  20. self.tab_2 = ttk.Frame(self.tab_control)
  21. self.tab_control.add(self.tab_1, text = 'tab 1')
  22. self.tab_control.add(self.tab_2, text = 'tab 2')
  23. self.tab_control.pack(fill = 'both', expand = 1)
  24.  
  25. self.channel_1 = Channel(self.tab_channel_1)
  26. self.channel_2 = Channel(self.tab_channel_2)
  27.  
  28. if __name__ == "__main__":
  29. root = tk.Tk()
  30. main_window = MainApplication(root) # <<<< here defined main_window
  31. main_window.pack(side="top", fill="both", expand=True)
  32. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement