Guest User

Untitled

a guest
Feb 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. from tkinter import*
  2. from functools import partial
  3. from tkinter import messagebox
  4.  
  5. class Placar(object):
  6.  
  7. def __init__(self, janela, local, info = {'casa':0, 'visitante':0, 'listaPonto':[]}):
  8.  
  9.  
  10. self.janela = janela
  11. self.info = info
  12. self.local = local
  13.  
  14. #Definindo Cor
  15.  
  16. color_background = 'black'
  17. cor_widget = 'white'
  18. fonte = ("Arial", 30, "bold")
  19.  
  20. #Configurações da Tela
  21.  
  22. self.janela['bg'] = color_background
  23. self.janela.resizable(False, False)
  24. #Icone da janela self.janela.iconbitmap(r'C:UserslucasOneDriveÁrea de TrabalhoPlacar-Basqueteicons-land-sport-basketball-ball.ico')
  25.  
  26. #Labels
  27.  
  28. lb_casa = Label(self.janela, text = "HOME", foreground = cor_widget, font = fonte, bg = color_background).place(x = 30, y = 100)
  29. lb_visitante = Label(self.janela, text = "GUEST", foreground = cor_widget, font = fonte, bg = color_background).place(x = 320, y = 100)
  30. self.lbponto_casa = Label(self.janela, text = str(self.info['casa']), font = ('Arial', 20, 'bold'), foreground = cor_widget, bg = color_background)
  31. self.lbponto_visitante = Label(self.janela, text = str(self.info['visitante']), font = ('Arial', 20, 'bold'), foreground = cor_widget, bg = color_background)
  32. self.lb_local = Label(self.janela, text = f"Local: {self.local}", font = ('Arial', 25, 'bold'), foreground = cor_widget, bg = color_background)
  33. lb_vs = Label(self.janela, text = 'VS', font = fonte, foreground = cor_widget, bg = color_background).place(x = 220, y = 100)
  34.  
  35. #Buttons
  36.  
  37. self.bt_pontuar = Button(self.janela, text = "Pontuar", font = ('Arial', 14, 'bold'), foreground = 'black', command = partial(self.identificar_time, True))
  38. self.bt_voltarponto = Button(self.janela, text = "Voltar pontuação", font = ('Arial', 14, 'bold'), foreground = 'black', command = partial(self.voltarPonto, True))
  39. self.bt_finalizar = Button(self.janela, text = "Finalizar", font = ('Arial', 14, 'bold'), foreground = 'black', command = partial(self.finalizar, True))
  40. self.bt_alterarLocal = Button(self.janela, text = "Alterar local", font = ("Arial", 10, 'bold'), foreground = 'black', command = partial(self.alterarLocal, True))
  41.  
  42. #Empacotamento
  43.  
  44. self.lbponto_casa.place(x = 82, y = 160)
  45. self.lbponto_visitante.place(x = 372, y = 160)
  46. self.bt_pontuar.place(x = 150, y = 300, width = 200)
  47. self.bt_voltarponto.place(x = 150, y = 350, width = 200)
  48. self.bt_finalizar.place(x = 150, y = 400, width = 200)
  49. self.bt_alterarLocal.place(x = 170, y = 60, width = 150, height = 25)
  50. self.lb_local.place(x = 130, y = 10)
  51.  
  52.  
  53. def identificar_time(self, click):
  54.  
  55. if click is True:
  56.  
  57. #Escondendo os botões
  58.  
  59. self.bt_pontuar.place_forget()
  60. self.bt_voltarponto.place_forget()
  61. self.bt_finalizar.place_forget()
  62. self.bt_alterarLocal.place_forget()
  63.  
  64. #Criando os CheckButtons e o Label
  65.  
  66. self.cbt1 = Checkbutton(self.janela, bg = "black", command = partial(self.identificar_ponto, "casa", True))
  67. self.cbt2 = Checkbutton(self.janela, bg = "black", command = partial(self.identificar_ponto, "visitante", False))
  68. self.aux = None
  69. self.aux2 = False
  70. self.lb = Label(self.janela, text = "Selecione um time", bg = "black", font = ("Arial", 14, "bold"), foreground = "white")
  71.  
  72. #Empacotando
  73.  
  74. self.cbt1.place(x = 81, y = 200)
  75. self.cbt2.place(x = 371, y = 200)
  76. self.lb.place(x = 160, y = 220)
  77.  
  78. def verificaBotao(self):
  79.  
  80. if self.aux == True and self.aux2 == False:
  81.  
  82. self.cbt2.deselect()
  83. self.time = "casa"
  84. self.aux = False
  85.  
  86. else:
  87.  
  88. self.cbt1.deselect()
  89. self.time = "visitante"
  90. self.aux = True
  91.  
  92. def identificar_ponto(self, time, select):
  93.  
  94. #Alterando o Label
  95. self.time = time
  96. self.lb['text'] = "Quantos pontos?"
  97. self.lb.place(x = 160, y = 220)
  98.  
  99. #Criando os CheckButtons
  100.  
  101. self.cbt3 = Checkbutton(self.janela, text = "1 ponto", font = ("Arial", 14, 'bold'), bg = 'black', foreground = 'white', command = partial(self.addPonto, 1))
  102. self.cbt4 = Checkbutton(self.janela, text = "2 pontos", font = ("Arial", 14, 'bold'), bg = 'black', foreground = 'white', command = partial(self.addPonto, 2))
  103. self.cbt5 = Checkbutton(self.janela, text = "3 pontos", font = ("Arial", 14, 'bold'), bg = 'black', foreground = 'white', command = partial(self.addPonto, 3))
  104.  
  105. #Empacotando
  106.  
  107. self.cbt3.place(x = 80, y = 340)
  108. self.cbt4.place(x = 200, y = 340)
  109. self.cbt5.place(x = 320, y = 340)
  110.  
  111. if select is True:
  112.  
  113. self.time = 'casa'
  114. self.cbt2.deselect()
  115. select = False
  116.  
  117. else:
  118.  
  119. self.time = 'visitante'
  120. self.cbt1.deselect()
  121. select = True
  122.  
  123. #self.verificaBotao()
  124.  
  125. def addPonto(self, ponto):
  126.  
  127. self.info[self.time] += ponto
  128. self.info['listaPonto'].append({self.time:ponto})
  129.  
  130. if self.time == 'casa':
  131. self.lbponto_casa['text'] = self.info[self.time]
  132. else:
  133. self.lbponto_visitante['text'] = self.info[self.time]
  134.  
  135. self.lb.destroy()
  136. self.cbt1.destroy()
  137. self.cbt2.destroy()
  138. self.cbt3.destroy()
  139. self.cbt4.destroy()
  140. self.cbt5.destroy()
  141.  
  142. self.bt_pontuar.place(x = 150, y = 300, width = 200)
  143. self.bt_voltarponto.place(x = 150, y = 350, width = 200)
  144. self.bt_finalizar.place(x = 150, y = 400, width = 200)
  145. self.bt_alterarLocal.place(x = 170, y = 60, width = 150, height = 25)
  146.  
  147. def voltarPonto(self, click):
  148.  
  149. if click is True:
  150.  
  151. if len(self.info['listaPonto']) == 0:
  152.  
  153. erro = messagebox.showinfo("", "Você não adicionou nenhuma pontuação a base de pontos.")
  154.  
  155. else:
  156.  
  157. ultimoPonto = len(self.info['listaPonto']) - 1
  158.  
  159. for i in self.info['listaPonto'][ultimoPonto].keys():
  160.  
  161. self.time = i
  162.  
  163. for i in self.info['listaPonto'][ultimoPonto].values():
  164.  
  165. self.ponto = i
  166.  
  167. self.info[self.time] -= self.ponto
  168.  
  169. if self.time == 'casa':
  170.  
  171. self.lbponto_casa['text'] = self.info[self.time]
  172.  
  173. else:
  174.  
  175. self.lbponto_visitante['text'] = self.info[self.time]
  176.  
  177. self.info['listaPonto'].pop()
  178.  
  179. def finalizar(self, click):
  180.  
  181. if click is True:
  182.  
  183. if self.info['casa'] > self.info['visitante']:
  184.  
  185. venceu = messagebox.showinfo("", "O time da Casa venceu!")
  186.  
  187. elif self.info['casa'] < self.info['visitante']:
  188.  
  189. venceu = messagebox.showinfo("", "O time dos Visitantes venceram!")
  190.  
  191. else:
  192.  
  193. empate = messagebox.showinfo("", "Empate!")
  194.  
  195. self.info['casa'] = 0
  196. self.info['visitante'] = 0
  197. self.lbponto_casa['text'] = self.info['casa']
  198. self.lbponto_visitante['text'] = self.info['visitante']
  199. self.info['listaPonto'] = []
  200.  
  201. def alterarLocal(self, click):
  202.  
  203. if click is True:
  204.  
  205. self.bt_alterarLocal.place_forget()
  206. self.ent = Entry(self.janela)
  207. self.bt = Button(self.janela, text = "Confirmar", font = ("Arial", 10, 'bold'), foreground = 'black', command = partial(self.alterar, True))
  208. self.ent.place(x = 150, y = 60, width = 110)
  209. self.bt.place(x = 270, y = 60)
  210.  
  211. def alterar(self, click):
  212.  
  213. if click is True:
  214. self.lb_local['text'] = f"Local: {self.ent.get()}"
  215. self.ent.destroy()
  216. self.bt.destroy()
  217. self.bt_alterarLocal.place(x = 170, y = 60, width = 150, height = 25)
  218.  
  219. janela = Tk()
  220. Placar(janela, "Indefinido")
  221. janela.title("Placar de Basquete")
  222. janela.geometry("500x500")
  223. janela.mainloop()
Add Comment
Please, Sign In to add comment