Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Kars Jansens
Kars Jansens
5,348 Points

How do I change information in a label? [PYTHON]

Hello, me and my friend are trying to make something because we have no school thanks to the corona virus. The what we want to do for now is to have a screen at first where you give your name, then the name is made in to a file with the file name being the same as the name you gave, that works. Then you go to the next page where you type something in and what you have typt will be saved in the file you just created or already existed and a label bellow the 'entry' will show everything you have typed, it can be more than only the last one

'''from tkinter import * import os import os.path import sys

total_chat = ""

def file_chat(): save_path_chatname = 'C:/Users/luc-s/Desktop/productivity/Python/chat/users' completeName1 = os.path.join(save_path_chatname, Chatname.get()) file = open(completeName1, "a") file.write(chat.get() + "\n")

total_chat = total_chat + chat.get()

file.close()

def user_open(): global chat name = Chatname.get()

 #scherm weergaven
screen1 = Tk()
screen1.geometry("500x500")
screen1.title("Chatting")


#tekst balk
if len(name) >= 10:
    Label(screen1, text = "welkom {} \n now you can chat with other people".format(name), bg = "grey", width = "500", height = "2", font = ("Calibri",13)).pack()
    Label(screen1, text = "").pack()

else:
    Label(screen1, text = "welkom {} now you can chat with other people".format(name), bg = "grey", width = "500", height = "2", font = ("Calibri",13)).pack()
    Label(screen1, text = "").pack()


chat = StringVar()
save_path_chatname1 = 'C:/Users/luc-s/Desktop/productivity/Python/chat/users'
completeName1 = os.path.join(save_path_chatname1, name)



chat = Entry(screen1, textvariable = chat)
chat.pack()
Button(screen1, text = "send", command = file_chat).pack()




Label(screen1, text = total_chat, bg = "white", width = "500", height = "400", borderwidth = "2", font = ("Calibri", 13)).pack()

def chat(): #name is chat name

name = Chatname.get()

screen.destroy()
print(name)

#naam zoeken
save_path = 'C:/Users/luc-s/Desktop/productivity/Python/chat/users'
list_of_files = os.listdir(save_path)

if name in list_of_files:
    user_open()

else:



    #naam opslaan
    print("SUCCEEDED")

    save_path_chatname = 'C:/Users/luc-s/Desktop/productivity/Python/chat/users'
    completeName1 = os.path.join(save_path_chatname, name)

    file = open(completeName1, "w")
    file.close()
    user_open()

def main_screen(): global screen global Chatname

#scherm weergaven
screen = Tk()
screen.geometry("250x250")
screen.title("Chatting")

#tekst balk
Label(text = "Chat", bg = "grey", width = "250", height = "2", font = ("Calibri",13)).pack()
Label(text = "").pack()

#username
Label(screen, text = "Please enter your username ", borderwidth = 2, relief = "groove" ).pack()
Label(screen, text = "").pack()

Chatname = StringVar()
Label(screen, text = "Username ").pack()
Chatname_entry1 = Entry(screen, textvariable = Chatname)
Chatname_entry1.pack()
Label(screen, text = "").pack()

#button chat
Button(text = "Login", height = "2", width = "30", command = chat).pack()
Label(text = "").pack()

screen.mainloop()

main_screen() '''python

https://gyazo.com/2eff43dd79b59a4a58cab14e880d9b27 the list of all the things I've made up should come in the big white square right after I've sent it, if I'm sending things again after then it should just be next to what's already been sent.

I have been trying for over 2,5 hours, if you can help me. Please say what we can do.

Thank you for helping me.

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

You might be interested in checking out EasyGUI or Guizero as an easier option to get your prototype going. Both are wrappers of Tkinter (TK) and easier to implement. Of the two, Easygui is easier to get going on, but Guizero is being actively developed.

http://easygui.sourceforge.net/

https://lawsie.github.io/guizero/