0

I'm new in python Tkinter and finding an issue here. I'm trying to get input from the user without pressing enter and want to use the input as updated label2. However, I'm getting an updated label only when while loop finish executing (only last input is getting displayed). Can you please help me to know where I am going wrong?

import tkinter as tk
import msvcrt

root= tk.Tk()
myCanvas = tk.Canvas(root, width = 500, height = 200)
myCanvas.pack()

def do_printing():
    count=1
    while (count>0):
        print('Count before= ',count)
        while 1:
            input1 = msvcrt.getwch()
            count=count+1
            break
        label2 = tk.Label(root, font=('Arial', 20))
        label2.config(text=input1)
        myCanvas.create_window(100, 50, window=label2)
        if count==7:
            break
    print('finished')

B1 = tk.Button(root, text ="Option 1", font=('Courier', 12), command= do_printing)
myCanvas.create_window(40, 30, window=B1)

root.mainloop()
avocadoLambda
  • 1,332
  • 7
  • 16
  • 33
  • 3
    First you have to understand [Event-driven_programming](https://en.m.wikipedia.org/wiki/Event-driven_programming). Read through [`[tkinter] event driven programming`](https://stackoverflow.com/search?q=is%3Aanswer+%5Btkinter%5D+event+driven+programming+entry) and [Tkinter understanding mainloop](https://stackoverflow.com/a/29158947/7414759) – stovfl Jun 18 '20 at 19:40
  • You create new label for each character pressed and put it at the same location, so why do you expect to see all the characters? – acw1668 Jun 19 '20 at 01:08

0 Answers0