Advertisement
rebeccacc

cliente

Jun 10th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. from tkinter import *
  2. import socket
  3. host = socket.gethostname()
  4. port = 9990
  5. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  6. s.connect((host, port))
  7.  
  8. i = 1
  9. def play():
  10. def letra():
  11. if len(entrada.get())>1:
  12. erro = Tk()
  13. erro.geometry("180x100+200+200")
  14. erro.title("ERRO")
  15. msgerro = Label(erro, text = "Insira a letra")
  16. msgerro.place(x = "50", y = "50")
  17. else:
  18. op = str(1).encode("utf8")
  19. s.send(op)
  20.  
  21. pegaletra = str(entrada.get()).strip().encode("utf8")
  22. s.send(pegaletra)
  23.  
  24. entrada.delete(0, END)
  25.  
  26. msg = s.recv(1024).decode("utf8")
  27. lblmsg["text"] = msg
  28.  
  29.  
  30. forca = s.recv(1024)
  31. forca = forca.decode("utf8")
  32. lblforca["text"] = forca
  33.  
  34. def palavra():
  35. if len(entrada.get())<=1:
  36. erro = Tk()
  37. erro.geometry("180x100+200+200")
  38. erro.title("ERRO")
  39. msgerro = Label(erro, text = "Insira a palavra")
  40. msgerro.place(x = "50", y = "50")
  41.  
  42. else:
  43. op = str(2).encode("utf8")
  44. s.send(op)
  45. pegapalavra = str(entrada.get()).strip().encode("utf8")
  46. s.send(pegapalavra)
  47.  
  48. entrada.delete(0, END)
  49.  
  50. msg = s.recv(1024).decode("utf8")
  51. lblmsg["text"] = msg
  52.  
  53. forca = s.recv(1024).decode("utf8")
  54. lblforca["text"] = forca
  55.  
  56. btnpalavra.place(x="100", y="175")
  57. btnreinicia = Button(janela2, text="Reiniciar jogada", command=playagain)
  58. btnreinicia.place(x="210", y="175")
  59.  
  60. def playagain():
  61. op = str(1).encode("utf8")
  62. s.send(op)
  63.  
  64. rcv = s.recv(1024)
  65. rcv = rcv.decode("utf8")
  66. lblforca["text"] = "A palavra tem %s letras" %rcv
  67. lblmsg["text"] = ""
  68.  
  69.  
  70. janela2 = Tk()
  71. janela2.geometry("400x300+200+200")
  72. entrada = Entry(janela2, text="")
  73. entrada.place(x="100", y="150")
  74. lblforca = Label(janela2, text = "forca aqui")
  75. lblforca.place(x = "235", y = "100")
  76. lblmsg = Label(janela2, text="mensagem")
  77. lblmsg.place(x="235", y="200")
  78. btnletra = Button(janela2, text = "Chutar letra", command = letra)
  79. btnletra.place(x = "235", y = "147")
  80. btnpalavra = Button(janela2, text="Chutar palavra", command = palavra)
  81. btnpalavra.place(x="150", y="175")
  82.  
  83. op = str(1).encode("utf8")
  84. s.send(op)
  85.  
  86. r = s.recv(1024)
  87. r = r.decode("utf8")
  88.  
  89. lblforca["text"] = "A palavra tem %s letras" %r
  90.  
  91. janela2.mainloop()
  92.  
  93.  
  94. def mudajanela():
  95. janela.destroy()
  96. play()
  97.  
  98. def howtoplay():
  99. janela.destroy()
  100. janela2 = Tk()
  101. janela2.geometry("400x300+200+200")
  102. btn = Label(janela2, text="ok")
  103. btn.place(x="150", y="150")
  104. janela2.mainloop()
  105.  
  106. janela = Tk()
  107. janela.geometry("400x300+200+200")
  108.  
  109. btn = Button(janela, text = "START", command = mudajanela)
  110. btn.place(x = "185", y = "95")
  111. btnsobre = Button(janela, text = "Como jogar?",command = howtoplay)
  112. btnsobre.place(x = "170", y = "130")
  113.  
  114.  
  115. janela.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement