Advertisement
Faherya

POO - Tkinter

Sep 20th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import ttk
  3.  
  4. class ExampleProject:
  5.  
  6.     def __init__(self):
  7.         """ Inicia o programa. """
  8.  
  9.         self.create_vocab()
  10.         self.create_window()
  11.         self.create_objects(self.root)
  12.         self.dispose_objetcs()
  13.         self.update()
  14.         self.start()
  15.  
  16.     def create_vocab(self):
  17.         """ Cria os textos a serem usados na Interface. """
  18.  
  19.         self.text_a = "Texto 1"
  20.         self.text_b = "Texto 2"
  21.         self.text_c = "Texto 3"
  22.  
  23.     def create_window(self):
  24.         """ Cria a janela. """
  25.  
  26.         self.root = Tk()
  27.  
  28.     def create_objects(self, root):
  29.         """ Cria individualmente cada grupo de objetos. """
  30.  
  31.         self.create_buttons(self.root)
  32.         self.create_labels(self.root)
  33.  
  34.     def create_buttons(self, root):
  35.         """ Cria os botões.  """
  36.  
  37.         self.button_a = ttk.Button(root, text="A", command=self.sample_function)
  38.         self.button_b = ttk.Button(root, text="B", command=self.sample_function)
  39.         self.button_c = ttk.Button(root, text="C", command=self.sample_function)
  40.  
  41.     def create_labels(self, root):
  42.         """ Cria os textos da janela. """
  43.  
  44.         self.ui_text_a = ttk.Label(root, textvariable=self.text_a)
  45.         self.ui_text_b = ttk.Label(root, textvariable=self.text_b)
  46.         self.ui_text_c = ttk.Label(root, textvariable=self.text_c)
  47.  
  48.     def dispose_objetcs(self):
  49.         """ Distribui os grupos de objetos na tela. """
  50.  
  51.         self.dispose_buttons()
  52.         self.dispose_labels()
  53.  
  54.     def dispose_buttons(self):
  55.         """ Distribui os botões na tela. """
  56.  
  57.         self.button_a.pack()
  58.         self.button_b.pack()
  59.         self.button_c.pack()
  60.  
  61.     def dispose_labels(self):
  62.         """ Distribui os textos na janela. """
  63.  
  64.         self.ui_text_a.pack()
  65.         self.ui_text_b.pack()
  66.         self.ui_text_c.pack()
  67.  
  68.     def sample_function(self):
  69.         """ Função de exemplo usada pelos botões. """
  70.  
  71.         pass
  72.  
  73.     def start(self):
  74.         """ Inicia o loop da janela. """
  75.  
  76.         self.root.mainloop()
  77.  
  78.     def update(self):
  79.         """ Atualiza a janela e seus elementos. """
  80.  
  81.         self.root.update()
  82.  
  83. # Iniciando:
  84. program = ExampleProject()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement