Aug-15-2019, 11:36 AM
(This post was last modified: Aug-15-2019, 11:36 AM by baseball2201.)
(Aug-15-2019, 11:05 AM)Larz60+ Wrote: show code
Here's a part - I'm having issues with what I commented out. I notice that this stops the terminal from continuing to read input, which I don't want at all. I want input to constantly get processed and not wait for one task to get done to move on, as the user will be pressing these keys frequently. I also am not sure how to simulate a keydown/keyup in here and would prefer that for getting the shape to appear/disappear rather than to use a regular timer for making the shape disappear.
import tkinter as tk def enter_pressed(event): print("Key pressed: ENTER") box = c.create_rectangle(50, 50, 100, 100, fill="red") # root.after(3000, c.delete(box)) def space_pressed(event): print("Key pressed: SPACE") def main(): root.bind("<Return>", enter_pressed) root.bind("<space>", space_pressed) root.mainloop() root = tk.Tk() root.title("My app") root.geometry('500x500') c = tk.Canvas(root, height=500, width=500, bg="blue") c.pack() main()