commit
75f5dc8749
|
@ -11,15 +11,15 @@ import PySimpleGUI as sg
|
|||
First parameter is the tkinter event string. These are things like <FocusIn> <Button-1> <Button-3> <Enter>
|
||||
Second parameter for windows is an entire key, for elements is something added onto a key. This key or modified key is what is returned when you read the window.
|
||||
If the key modifier is text and the key is text, then the key returned from the read will be the 2 concatenated together. Otherwise your event will be a tuple containing the key_modifier value you pass in and the key belonging to the element the event happened to.
|
||||
|
||||
Copyright 2021 PySimpleGUI
|
||||
"""
|
||||
sg.theme('Dark Blue 3')
|
||||
|
||||
def main():
|
||||
layout = [ [sg.Text('Move mouse over me', key='-TEXT-')],
|
||||
[sg.In(key='-IN-')],
|
||||
[sg.Button('Right Click Me', key='-BUTTON-'), sg.Button('Right Click Me2', key=(2,3)),sg.Button('Exit'),
|
||||
]
|
||||
]
|
||||
[sg.Button('Right Click Me', key='-BUTTON-'), sg.Button('Right Click Me2', key=(2,3)),sg.Button('Exit'),]]
|
||||
|
||||
window = sg.Window('Window Title', layout, finalize=True)
|
||||
|
||||
|
@ -30,7 +30,7 @@ def main():
|
|||
window['-TEXT-'].bind('<Enter>', '+MOUSE OVER+')
|
||||
window['-TEXT-'].bind('<Leave>', '+MOUSE AWAY+')
|
||||
window['-IN-'].bind('<FocusIn>', '+INPUT FOCUS+')
|
||||
|
||||
window.bind('<Enter>', '* WINDOW ENTER *')
|
||||
while True: # Event Loop
|
||||
event, values = window.read()
|
||||
print(event, values)
|
||||
|
@ -40,4 +40,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
|
@ -0,0 +1,31 @@
|
|||
import PySimpleGUI as sg
|
||||
"""
|
||||
Demo Hotkey
|
||||
|
||||
Want a keyboard hotkey to cause your program to take some action
|
||||
that's identical to a button being clicked?
|
||||
|
||||
Well... that's 1 line of code that's needed.
|
||||
|
||||
This line binds the F10 keybaord key to the window. It produces a "Go" event:
|
||||
window.bind('<F10>', 'Go')
|
||||
|
||||
Copyright 2021 PySimpleGUI
|
||||
"""
|
||||
|
||||
layout = [ [sg.Text('Press F10 to get same result as clicking "Go" button')],
|
||||
[sg.Input(key='-IN-')],
|
||||
[sg.Output(size=(30,8))],
|
||||
[sg.Button('Go'), sg.Button('Exit')] ]
|
||||
|
||||
window = sg.Window('Window Title', layout, finalize=True)
|
||||
|
||||
window.bind('<F10>', 'Go')
|
||||
|
||||
while True: # Event Loop
|
||||
event, values = window.read()
|
||||
print(event, values)
|
||||
if event in (None, 'Exit'):
|
||||
break
|
||||
|
||||
window.close()
|
Loading…
Reference in New Issue