fork download
  1. import tkinter as tk
  2. from functools import partial
  3.  
  4.  
  5. class Botao(tk.Button):
  6.  
  7. def clique(self, saida, vezes):
  8. saida['text'] = 'Clicou {} !'.format(vezes)
  9.  
  10. def contagem(self, saida):
  11. valor = 0
  12. def retorna():
  13. nonlocal valor
  14. valor += 1
  15. self.clique(saida, valor)
  16. return retorna
  17.  
  18.  
  19. class App(object):
  20.  
  21. def __init__(self):
  22. self.root = tk.Tk()
  23. self.fonte = ('Comic Sans MS', 14, 'bold')
  24. self.frame1 = tk.Frame(self.root)
  25. self.frame2 = tk.Frame(self.root)
  26. self.botao1 = Botao(self.frame1, text = 'Clique Aqui !', font = self.fonte)
  27. self.saida1 = tk.Label(self.frame1, text = 'Ainda não clicou !', fg = 'red', font = self.fonte)
  28. self.botao1['command'] = self.botao1.contagem(self.saida1)
  29. self.saida1.pack()
  30. self.botao1.pack()
  31. self.botao2 = Botao(self.frame1, text = 'Clique Aqui !', font = self.fonte)
  32. self.saida2 = tk.Label(self.frame1, text = 'Ainda não clicou !', fg = 'red', font = self.fonte)
  33. self.botao2['command'] = self.botao2.contagem(self.saida2)
  34. self.saida2.pack()
  35. self.botao2.pack()
  36. self.frame1.pack()
  37.  
  38. app = App()
Runtime error #stdin #stdout #stderr 0.06s 15256KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 38, in <module>
  File "./prog.py", line 22, in __init__
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable