'i want my code to not work while i click on w,a,s,d keys
i need my python code which will work unless i click "W,A,S,D" Keys
i dont know how to use case thing
import Tkinter as tk
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent, width=400, height=400)
self.label = tk.Label(self, text="last key pressed: ", width=20)
self.label.pack(fill="both", padx=100, pady=100)
self.label.bind
self.label.bind
self.label.bind
self.label.bind
# give keyboard focus to the label by default, and whenever
# the user clicks on it
self.label.focus_set()
self.label.bind("<1>", lambda event: self.label.focus_set())
Solution 1:[1]
import Tkinter as tk
stops = ["W","S","D","A"]
class Example(tk.Frame):
def __init__(self, parent,stops):
tk.Frame.__init__(self, parent, width=400, height=400)
self.label = tk.Label(self, text="last key pressed: ", width=20)
self.label.pack(fill="both", padx=100, pady=100)
# something like that you need
for stop in stops:
if stop == (self.label,parent):
return
self.label.bind
self.label.bind
self.label.bind
self.label.bind
# give keyboard focus to the label by default, and whenever
# the user clicks on it
self.label.focus_set()
self.label.bind("<1>", lambda event: self.label.focus_set())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Konstantinos K. |
