Advertisement
Rnery

How program with tkinter..

Aug 4th, 2021 (edited)
220
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | Source Code | 1 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Gerando exceções de import
  5. try:
  6.     import tkinter as tk
  7. except ImportError as error:
  8.     print(error)
  9.  
  10. root = tk.Tk()
  11.  
  12. '''
  13. Conceito de componetização de botões
  14. Botão de Quit
  15. '''
  16. button = tk.Button(root, text = 'Quit', command = root.destroy)
  17.  
  18. '''
  19. O place serve pra colocar o botão onde eu quiser, assim como o grid
  20. e o pack
  21. '''
  22. button.place(x = '30', y = '30')
  23.  
  24. '''
  25. O configure eu coloco estilos no botão
  26. '''
  27. button.configure(justify = 'center', relief = 'ridge', bd = '0',
  28.                  background = 'white')
  29.  
  30. '''
  31. Função de imprimir no terminal com botões widgets
  32. Padrão snake_case PEP8: https://www.python.org/dev/peps/pep-0008/
  33. '''
  34. def imprimir_no_terminal():
  35.     print('Olá mundo!')
  36.  
  37. button_impress = tk.Button(root, text = 'Clique Aqui!',
  38. command = lambda: imprimir_no_terminal())
  39.  
  40. button_impress.place(x = '100', y = '30')
  41.  
  42.  
  43. root.title('Tkinter - Button')
  44. root.geometry('300x300')
  45. root.resizable(False, False)
  46. root.eval('tk::PlaceWindow . center')
  47. root.mainloop()
  48.  
Tags: python tkinter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement