Created
November 6, 2019 09:42
-
-
Save ShivamJoker/66982279963721bc8b60dc6521224743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from pynput import keyboard | |
root = tk.Tk() | |
root.title("WiFi Remote") | |
root.geometry("600x400") | |
root.resizable(0, 0) | |
focusedtEntry = 0 | |
# --functions--- | |
def getInputs(): | |
inputTopVal = str(inputTop.get()) | |
inputCenter.delete(0, 50) | |
# inputCenter.insert(1, inputTopVal) | |
def handleFocus(event): | |
global focusedtEntry | |
focusedtEntry = event.widget | |
def on_press(key): | |
# we will store the previous value | |
previousValue = str(focusedtEntry.get()) | |
focusedtEntry.delete(0, 50) | |
if previousValue == "": | |
focusedtEntry.insert(1, str(key)) | |
else: | |
focusedtEntry.insert(1, previousValue + " + " + str(key)) | |
titleLabel = tk.Label(text="Press the key in input fields") | |
titleLabel.grid(column=1, row=0) | |
inputTop = tk.Entry() | |
inputTop.grid(column=1, row=1) | |
inputLeft = tk.Entry() | |
inputLeft.grid(column=0, row=2) | |
inputCenter = tk.Entry() | |
inputCenter.grid(column=1, row=2) | |
inputRight = tk.Entry() | |
inputRight.grid(column=2, row=2) | |
inputBottom = tk.Entry() | |
inputBottom.grid(column=1, row=3) | |
useMediaKeysCheckbox = tk.Checkbutton(text="Media Keys") | |
useMediaKeysCheckbox.grid(column=1, row=6) | |
saveFileBtn = tk.Button(text="Save Settings", command=getInputs) | |
saveFileBtn.grid(column=1, row=8) | |
saveFileBtn = tk.Button(text="Reset", command=getInputs) | |
saveFileBtn.grid(column=1, row=10) | |
# Collect events until released | |
listener = keyboard.Listener( | |
on_press=on_press | |
) | |
listener.start() | |
# binding to get which item is in focus | |
root.bind("<FocusIn>", handleFocus) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment