Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import socket
- host = socket.gethostname()
- port = 9990
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((host, port))
- i = 1
- def play():
- def letra():
- if len(entrada.get())>1:
- erro = Tk()
- erro.geometry("180x100+200+200")
- erro.title("ERRO")
- msgerro = Label(erro, text = "Insira a letra")
- msgerro.place(x = "50", y = "50")
- else:
- op = str(1).encode("utf8")
- s.send(op)
- pegaletra = str(entrada.get()).strip().encode("utf8")
- s.send(pegaletra)
- entrada.delete(0, END)
- msg = s.recv(1024).decode("utf8")
- lblmsg["text"] = msg
- forca = s.recv(1024)
- forca = forca.decode("utf8")
- lblforca["text"] = forca
- def palavra():
- if len(entrada.get())<=1:
- erro = Tk()
- erro.geometry("180x100+200+200")
- erro.title("ERRO")
- msgerro = Label(erro, text = "Insira a palavra")
- msgerro.place(x = "50", y = "50")
- else:
- op = str(2).encode("utf8")
- s.send(op)
- pegapalavra = str(entrada.get()).strip().encode("utf8")
- s.send(pegapalavra)
- entrada.delete(0, END)
- msg = s.recv(1024).decode("utf8")
- lblmsg["text"] = msg
- forca = s.recv(1024).decode("utf8")
- lblforca["text"] = forca
- btnpalavra.place(x="100", y="175")
- btnreinicia = Button(janela2, text="Reiniciar jogada", command=playagain)
- btnreinicia.place(x="210", y="175")
- def playagain():
- op = str(1).encode("utf8")
- s.send(op)
- rcv = s.recv(1024)
- rcv = rcv.decode("utf8")
- lblforca["text"] = "A palavra tem %s letras" %rcv
- lblmsg["text"] = ""
- janela2 = Tk()
- janela2.geometry("400x300+200+200")
- entrada = Entry(janela2, text="")
- entrada.place(x="100", y="150")
- lblforca = Label(janela2, text = "forca aqui")
- lblforca.place(x = "235", y = "100")
- lblmsg = Label(janela2, text="mensagem")
- lblmsg.place(x="235", y="200")
- btnletra = Button(janela2, text = "Chutar letra", command = letra)
- btnletra.place(x = "235", y = "147")
- btnpalavra = Button(janela2, text="Chutar palavra", command = palavra)
- btnpalavra.place(x="150", y="175")
- op = str(1).encode("utf8")
- s.send(op)
- r = s.recv(1024)
- r = r.decode("utf8")
- lblforca["text"] = "A palavra tem %s letras" %r
- janela2.mainloop()
- def mudajanela():
- janela.destroy()
- play()
- def howtoplay():
- janela.destroy()
- janela2 = Tk()
- janela2.geometry("400x300+200+200")
- btn = Label(janela2, text="ok")
- btn.place(x="150", y="150")
- janela2.mainloop()
- janela = Tk()
- janela.geometry("400x300+200+200")
- btn = Button(janela, text = "START", command = mudajanela)
- btn.place(x = "185", y = "95")
- btnsobre = Button(janela, text = "Como jogar?",command = howtoplay)
- btnsobre.place(x = "170", y = "130")
- janela.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement