Skip to content

Commit

Permalink
Explanation on binding keys #303
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisteach committed Nov 26, 2017
1 parent b9b70f0 commit e9d0063
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/mkdocs/docs/pythonEvents.md
Expand Up @@ -107,6 +107,22 @@ Link a function to the ```<Enter>``` key
Unlink a function from the ```<Enter>``` key

You may also want to bind other keys to events.
See [here](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm) for a detailed list of the *Event Formats*.

```python
from appJar import gui
def keyPress(key):
if key == "<Up>":
app.increaseFont()
elif key == "<Down>":
app.decreaseFont()

app = gui("Button Demo")
app.addLabel("title", "Press the arrow keys to change the font")
app.bindKey("<Up>", keyPress)
app.bindKey("<Down>", keyPress)
app.go()
```

* `.bindKey(key, function)`
Link the specified key to the specified function.
Expand Down
24 changes: 24 additions & 0 deletions examples/issues/issue303.py
@@ -0,0 +1,24 @@
import sys
sys.path.append("../../")
from appJar import gui

def press(btn):
print(btn)
if btn == "<Up>":
app.increaseFont()
else:
app.decreaseFont()

app=gui()
app.addLabel("title", "Red")
app.setBg("red")

app.bindKey("<Up>", press)
app.bindKey("<Down>", press)
app.bindKey("<Left>", press)
app.bindKey("<Right>", press)
app.bindKey("<Right>", press)
app.bindKey("<F1>", press)
app.bindKey("<F2>", press)

app.go()
14 changes: 14 additions & 0 deletions examples/issues/issue303_2.py
@@ -0,0 +1,14 @@
import sys
sys.path.append("../../")
from appJar import gui
def keyPress(key):
if key == "<Up>":
app.increaseFont()
elif key == "<Down>":
app.decreaseFont()

app = gui("Button Demo")
app.addLabel("title", "Press the arrow keys to change the font")
app.bindKey("<Up>", keyPress)
app.bindKey("<Down>", keyPress)
app.go()

0 comments on commit e9d0063

Please sign in to comment.