Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

Having problems with making a chat in python

So basically I am trying to make a chat using python and I want to make a GUI for it using tkinter, I run the code and everything is normal everything except my GUI, it should be showing the name of the one who sends the message and the message itself but instead of that it's showing {self.name}:{self.msg} and here is the code:

def sendMessage(self):
        self.textCons.config(state=DISABLED)
        while True:
              message = "{self.name}: {self.msg}"
              client.send(message.encode(FORMAT))
              break

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

for the message you have to do:

message = "{0}: {1}".format(self.name, self.msg)

then in your while loop you do:

while True:
    #do something
    break

that iterate only one time, so if you whant only one repetition you have to do:

#do something

esle if you want to do it more times you can use a for x in range() loop or a while loop where you stop if a condition ocurres


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.5k users

...