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


i want make basic program using python use raw_input() or input() ask person input string shell , not in python application window. have code:

import sys tkinter import *  gui = tk() gui.geometry('450x450+200+200') gui.title = ('lol')  label = label(text='my label').pack()   def ask_text():     new_text = input('input text here:\n')     change_text(new_text)  def change_text(new_text):     label2 = label(text=new_text).pack()     if new_text != 'stop_program':         ask_text()  ask_text() 

when run this, python application keeps bouncing on mac, , ask me input app opens after put stop_program. want open , change label instantly after type put. how preferably using tkinter?

thanks

i modified 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, not providing explanation, canlt spend more time on now. try code. note 1 thing: because user input console, tkinter window blocked during this. update label, want able close it, tkinter want respond events python stuck @ console input. multithreading needed here. , wrote in comment question, better ask user input tkinter entry widget, rather console.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -