Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...