How do I change change the text on a label to an input or raw_input from shell in python? How do I change change the text on a label to an input or raw_input from shell in python? tkinter tkinter

How do I change change the text on a label to an input or raw_input from shell in python?


I modified your code:

from tkinter import *class MyWindow(Frame):    def __init__(self, parent, *pargs, **kwargs):        Frame.__init__(self, parent, *pargs, **kwargs)        self.label_text = StringVar()        self.label_text.set("my label")        self.label = Label(self, textvariable = self.label_text)        self.label.pack()        self.after(1000, self.ask_text)    def ask_text(self):        while True:            new_text = input('Input text here: \n')            if new_text == 'stop_program':                self.master.quit()                break;            self.label_text.set(new_text)            self.label.update()    def change_text(self, new_text):        self.label["text"] = new_text        if new_text != 'stop_program':            self.ask_text()Gui = Tk()Gui.geometry('450x450+200+200')Gui.title = ('lol')my_window = MyWindow(Gui)my_window.pack()mainloop()

Sorry, for not providing explanation, as I canlt spend more time on it now. Just try the code. But note one thing: because you get user input from console, tkinter window will be blocked during this. It will update the label, but you want be able to close it, as tkinter want respond to any events as the python is stuck at console input. Probably some multithreading would be needed here. And as I wrote in the comment to the question, better would be to ask for user input from tkinter Entry widget, rather than from console.