Python Forum
Tkinter Generate/Delete Shapes with Keyboard Events
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Generate/Delete Shapes with Keyboard Events
#3
(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()
Reply


Messages In This Thread
RE: Tkinter Generate/Delete Shapes with Keyboard Events - by baseball2201 - Aug-15-2019, 11:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,946 Jul-29-2020, 07:13 PM
Last Post: deanhystad
  [Tkinter] Tkinter delete combobox content and not the list LagratteCchouette 4 8,547 Dec-29-2019, 11:04 AM
Last Post: LagratteCchouette
  [PyQt] Wonky Touch Events hessej 2 2,346 Nov-07-2019, 07:52 PM
Last Post: kozaizsvemira
  How to delete text from a tkinter Text widget? Tang 1 28,727 May-20-2018, 09:26 PM
Last Post: Larz60+
  [PyQt] touch events is not generating shridhara 0 3,415 Apr-23-2018, 11:39 AM
Last Post: shridhara
  [Tkinter] problem with button events Lubik_ 4 9,839 Dec-01-2017, 08:47 PM
Last Post: Windspar
  How can I draw en color shapes on python? MBlastSt 2 4,589 Oct-09-2017, 01:42 PM
Last Post: ichabod801
  PyQt5 events alekssandrap 1 7,637 Jan-31-2017, 03:53 PM
Last Post: Larz60+
  PyQt4 Touch events alekssandrap 2 7,209 Jan-28-2017, 01:05 PM
Last Post: alekssandrap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020